Error 2001: Operation Canceled

xMax

Registered User.
Local time
Yesterday, 22:12
Joined
Aug 7, 2006
Messages
35
I am getting an Error 2001 here and I can't seem to find what the error is:

Here's the code:

Private Sub cmdLogin_Click()
Dim query As String
Dim login As String
Dim thepassword1 As String
Dim thepassword2 As String
Dim validLogin As String
Dim correctPassword1 As String
Dim correctPassword2 As String
txtLogin.SetFocus
login = txtLogin.Text
txtPassword1.SetFocus
thepassword1 = txtPassword1.Text
txtPassword2.SetFocus
thepassword2 = txtPassword2.Text
txtLogin.SetFocus

validLogin = DLookup("LoginName", "[tblLogin]", "LoginName = " & txtLogin.Text)
MsgBox "validLogin"


If validLogin = login Then
correctPassword1 = DLookup("password1", "[tblLogin]", "LoginName = " & txtLogin.Text)
correctPassword2 = DLookup("password2", "[tblLogin]", "LoginName = " & txtLogin.Text)
If ((thepassword1 = correctPassword1) And (thepassword2 = correctPassword2)) Then
MsgBox "Correct Passwords Entered"
Else
MsgBox "Incorrect Passwords"
End If
Else
MsgBox "Invalid User Name"
End If

End Sub


The highlighted line is the 1st DLookUp line. Please tell me what's wrong.

Max
 
Ok I do not receive the Error 2001 but I now receive a Invalid Use of Null Value (if the login doesn't exist, then it should be null, and the same with passwords). What am I doing wrong here?
 
You've declared validLogin as String, which can not accept the Null that the DLookup will return if it finds no match. Try changing that to Variant.
 
Try this!!

Try this: Instead of using "LoginName = " & txtLogin.Text in the third parameter of the DLookup sentence, add single quotation marks, just like this:

"LoginName = ' " & txtLogin.Text & "'"

If this doesn't work, try using the full path to your form control (e.g, forms!your_form_name!txtLogin) without the .Text, that will fit perfectly.
 
This would be my preference:

validLogin = Nz(DLookup("LoginName", "tblLogin", "[LoginName]='" & txtLogin & "'"),"")
 

Users who are viewing this thread

Back
Top Bottom