Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run Time Error '2001' 2

Status
Not open for further replies.

jt643

Technical User
Jun 17, 2003
144
The following code is attached to a button's 'on click' where I am wanting to take the 'password' field from a 'databaselogon' form and DLookup my 'tblEmployees' table to make sure that the password entered does in fact correlate with the corresponding 'strEmpName' and 'strEmpPassword' on the 'tblEmployees' table:

'Check Value Of Password In tblEmployees To See If This Matches Value Chosen In UserName
If Me.Password.Value = DLookup("strEmpPassword", "tblEmployees", "[strEmpName]=" & Me.UserName.Value) Then
lngMyEmpID = Me.UserName.Value
'Close Logon Form And Open Splash Screen
sqlcmd = "DELETE from UserTemp WHERE UserName = '" & Forms!DatabaseLogon!UserName & "'"
sqlcmd2 = "INSERT into UserTemp (UserID,UserName) VALUES ('" & UserID & "','" & Forms!DatabaseLogon!UserName & "')"
DoCmd.RunSQL sqlcmd
DoCmd.RunSQL sqlcmd2
DoCmd.Close acForm, "DatabaseLogon", acSaveNo
DoCmd.OpenForm "MainMenu"
Else
MsgBox "Password Invalid! Please Try Again.", vbOKOnly, "Invalid Entry!"
Me.Password.SetFocus
End If

[End Code]

I receive a 'Run-Time Error '2001'' message telling me I have cancelled the previous operation. Thanks, in advance, for any assistance you can provide.
 
I recommend putting msgbox("line1") or some variation after each line to see which exact line is blowing it up.

Morgance

 
Ahhh yes, Run-Time Error 2001 - the famed "Kubrick maneuver".... :)


JT, I can't be absolutely sure here, but I think you might be running into a timing problem with your two SQL commands and/or the Form Close process.

1) If you DO NOT carry out the second "RunSQL..." guy that does the insert, do you still get the R/T error?

2) if you run the two SQL commands, but DO NOT close the form, do you still get the error?


Also, for sake of clarity, I might throw in an "exit Sub" right about here:


DoCmd.OpenForm "MainMenu"
[red]Exit Sub[/red]
Else


It's not really syntactically necessary, but it's a foolproof method to make sure that the ELSE.. logic never gets carried out.

Let us know...

Jim

Don't be sexist - Broads hate that.
Another free Access forum:
More Access help stuff at
 
Thank you both for your responses. To answer Jim's questions:

1) If you DO NOT carry out the second "RunSQL..." guy that does the insert, do you still get the R/T error?

I tweaked the code and commented out each SQL separately...both to no avail.

2) if you run the two SQL commands, but DO NOT close the form, do you still get the error?

I tried manipulating the Open/Close logic which produced the same results.

I am thinking that it has something to do with my syntax in the DLookup line--because no matter what I tweak below that line, the code blows up at that line.

 
Hi!

Assume the username is text, try text qualifiers:

[tt]If Me.Password.Value = DLookup("strEmpPassword", "tblEmployees", _
"[strEmpName]='" & Me.UserName.Value & "'")[/tt]

Roy-Vidar
 
jt,

why not just write VB code to do you check. Some would say it takes longer but you have wasted enuf time now to more than make up for the time to code. I straight path is often the fastest. Need the code, ask for it.

R
 
Thank you everyone for your assistance. RoyVidar, once again, your insight has proven extremely valuable! Rolliee, thank you for your suggestion as well.

I ended up using RoyVidar's code, and it worked great!

JT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top