DAO criteria type mismatch error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kisho87
    New Member
    • Apr 2010
    • 2

    DAO criteria type mismatch error

    i have coded a username password program via using DAO control
    created a ms access 7.0 DB file and linked with data1 control and used 2 textbox controls for username and password.
    For login cmd button i have written below codes
    Dim strCritaria As String
    strCritaria = " [Username] = ' " & txtuse.Text & " ' " And "[Password] = ' " & txtpass.Text & " ' "
    Data1.Recordset .MoveFirst
    Data1.Recordset .FindFirst (strCritaria)
    If Data1.Recordset .NoMatch Then
    MsgBox "Invalid Entry"
    txtuse.Text = ""
    txtpass.Text = ""
    Else
    MsgBox "Login Succussfull"
    End If
    in execution i am getting type mismatch runtime error 13 in strCritaria line
    any help regarding this will be appreciated...
    sorry i am new to vb6
  • PatMc
    New Member
    • Apr 2010
    • 1

    #2
    Error in criteria code

    Hi,
    If this line of criteria is correct then change it to the line I have modified below
    strCritaria = " [Username] = ' " & txtuse.Text & " ' " And "[Password] = ' " & txtpass.Text & " ' "

    Modified line
    strCritaria = " [Username] = ' " & txtuse.Text & " ' And [Password] = ' " & txtpass.Text & " ' "

    Comment

    • patjones
      Recognized Expert Contributor
      • Jun 2007
      • 931

      #3
      Also be careful about padding the criteria with spaces, as you have done. The way you've written out the criteria, if they type in "zepphead80 " for the user name, the criteria will read [Username] = ' zepphead80 '. If zepphead80 existed as a user in your table, it wouldn't be found. Modify the criteria as:

      Code:
      strCritaria = " [Username] = '" & txtuse.Text & "' And [Password] = '" & txtpass.Text & "'"

      which would then give you [Username] = 'zepphead80'.

      Pat

      Comment

      • kisho87
        New Member
        • Apr 2010
        • 2

        #4
        wow guys well done
        it works
        thank you
        PatMc & zepphead80

        Comment

        Working...