Run-time Error '13' : Type Mismatch (1 Viewer)

IbrahimL

New member
Local time
Yesterday, 22:10
Joined
Dec 5, 2012
Messages
2
Hello Everyone,
I have successfully created a login page for my Order Processing System. When I enter my Username and Password correctly it logs in successfully and moved onto my next form called 'frmWelcome'. However if I enter the incorrect Username and Password I get Error:

Run-time Error '13' : Type Mismatch

I have tried everything, anyone that can help me?


Code:
Option Compare Database
Option Explicit
Private Sub Form_load()
'When the form loads the enter form will open
DoCmd.OpenForm "frmLogin"
End Sub

Private Sub cmdLogin_Click()
'The dlookup funtion allows the records to be searched within the required table
    If txtPassword.Value = DLookup("[Password]", "tblUsers", "[UserName]='" & txtUserName.Value & "'") Then
   'This is opening the main menu and then closing the form enter
   DoCmd.OpenForm "frmWelcome"
   DoCmd.Close acForm, "frmLogin"
   'txtusername.Value = Null
   'txtpassword.Value = Null
 ElseIf (txtUserName.Value) Then
    MsgBox "Enter Username and Password", vbCritical, "Error"
    txtPassword.Value = ""
    txtUserName.SetFocus
    ElseIf (txtPassword.Value) Then
    MsgBox "Enter password", vbCritical, "Error"
    txtPassword.SetFocus
 Else
   'If incorrect details are entered into any of the fields and enter is selected this would display an error message
   MsgBox "Log in details are incorrect, Please try again", vbCritical, "Error"
   'Both the fields would clear
   txtUserName.Value = Null
   txtPassword.Value = Null
   txtUserName.SetFocus

 End If
End Sub

Private Sub txtUserName_LostFocus()
    'after the user leaves the colour text box, convert the entered
    'colour to proper case, e.g. all words start with upper case letters
    txtUserName.Value = StrConv(txtUserName, vbProperCase)
End Sub

Private Sub cmdExit_Click()
 'This closes the forms down completely
 DoCmd.Quit
End Sub
 
Last edited:

DJkarl

Registered User.
Local time
Today, 00:10
Joined
Mar 16, 2007
Messages
1,028
First, this is the VB.NET section so this should really be posted over in the VBA code area since that's what this code is.

Second, I suspect the error is on this lookup function
DLookup("[Password]", "tblUsers", "[UserName]='" & txtUserName.Value & "'")

If the user/pwd combination isn't found this will return a null value, comparing the textbox to a null is a no-no in VBA, try wrapping this with the NZ function.
 

Users who are viewing this thread

Top Bottom