• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 703
  • Last Modified:

How do I resolve the error "Run time error '2001': You canceled the previous operation" in an Access 2003 application?

I am developing an Access 2003 application using VBA code.
For my log on screen, I use a combobox control for the userID,
a text box to enter a password and a submit command button to validate the

the tblUserSecurity1 table has the following fields:
primary key    recordnum             AutoNumber
                              userID                     Text
                              securityLevel        Text
                              password                Text  

The combox displays the userID but is based on the following Row source:
SELECT tblUserSecurity1.recordnum, tblUserSecurity1.userID FROM tblUserSecurity1 ORDER BY [userID];  

My log on FORM code is as follows:
After the Login ID and password are entered, the following error occurs:

Run time error '2001':
You canceled the previous operation.

The system stops at the line:
strUSERRIGHTS = DLookup("secLevel", "tblUserSecurity1", "[recordnum]=" & Me.Combo25.Value)

 If IsNull(Me.Combo25) Or Me.Combo25 = "" Then
       MsgBox "You must enter a valid login ID.", vbOKOnly, "Required Data"
       Exit Sub
    End If
    'Check to see if data is entered into the password box
    If IsNull(Me.TxtPwd) Or Me.TxtPwd = "" Then
       MsgBox "You must enter a Password", vbOKOnly, "Required Data"
       Exit Sub
    End If
    If Me.TxtPwd.Value = DLookup("PASSWORD", "tblUserSecurity1", "[recordnum]=" & Me.Combo25.Value) Then
       strUSER = DLookup("UserID", "tblUserSecurity1", "[recordnum]=" & Me.Combo25.Value)
       strUSERRIGHTS = DLookup("secLevel", "tblUserSecurity1", "[recordnum]=" & Me.Combo25.Value)
       'DoCmd.Close acForm, "frmLogon", acSaveNo
       'DoCmd.OpenForm "frmCustomRpt"
       MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
    End If
    intLogonAttempts = intLogonAttempts + 1
    If intLogonAttempts > 3 Then
       MsgBox "You do not have access to this database.Please contact admin.", vbCritical, "Restricted Access!"
    End If
1 Solution
Rey Obrero (Capricorn1)Commented:
you mentioned "securityLevel" is the name of the field,

you are using "secLevel" in this line

strUSERRIGHTS = DLookup("secLevel", "tblUserSecurity1", "[recordnum]=" & Me.Combo25.Value)


strUSERRIGHTS = DLookup("securityLevel", "tblUserSecurity1", "[recordnum]=" & Me.Combo25.Value)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now