Runtime Error 2001: You canceled the previous operation.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AccessBeetle
    New Member
    • Jul 2009
    • 111

    Runtime Error 2001: You canceled the previous operation.

    I am creating simple login form with linked tables(atual tables are in SQL 2005) in access 2003.
    Here is my code.
    Code:
    Option Compare Database
    
    
    Private Sub cmdSignIn_Click()
    'Check to see if data is entered into the UserName combo box
    
        If IsNull(Me.txtUsername) Or Me.txtUsername = "" Then
          MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
            Me.txtUsername.SetFocus
            Exit Sub
        End If
    
        'Check to see if data is entered into the password box
    
        If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
          MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
            Me.txtPassword.SetFocus
            Exit Sub
        End If
    
        'Check value of password in tbl_ValUsers to see if this
        'matches value chosen in combo box
    
    [B]    If Me.txtPassword.Value = DLookup("Password", "RadioLog_tblValUsers", "[UserName] = " _
                             & Me.txtUsername.Value) Then[/B]
    
            UserName = Me.txtUsername.Value
    
            'Close logon form and open splash screen
    
            DoCmd.Close acForm, "frmLogin", acSaveNo
            DoCmd.OpenForm "Switchboard"
    
        Else
          MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
                "Invalid Entry!"
            Me.txtPassword.SetFocus
        End If
    
        'If User Enters incorrect password 3 times database will shutdown
    
        intLogonAttempts = intLogonAttempts + 1
        If intLogonAttempts > 3 Then
          MsgBox "You do not have access to this database.Please contact admin.", _
                   vbCritical, "Restricted Access!"
            Application.Quit
        End If
    
    End Sub
    
    Private Sub txtUsername_AfterUpdate()
    Me.txtPassword.SetFocus
    End Sub
    I am getting this run time error 2001 when I click on "Sign In" after entering Username and password. When I click on debug it takes me to the line in bold.
    Any clue what is going on?
  • ChipR
    Recognized Expert Top Contributor
    • Jul 2008
    • 1289

    #2
    Assuming the UserName field contains a string, you need to delimit it with quotes.
    Code:
    ..., "UserName = '" & txtUserName & "'") Then

    Comment

    • missinglinq
      Recognized Expert Specialist
      • Nov 2006
      • 3533

      #3
      One has to presume that txtUsername is Text, but your syntax
      Code:
      If Me.txtPassword.Value = DLookup("Password", "RadioLog_tblValUsers", "[UserName] = " & Me.txtUsername.Value) Then
      is only correct for a Numeric Datatype. For Text it would be :
      Code:
      If Me.txtPassword.Value = DLookup("Password", "RadioLog_tblValUsers", "[UserName] = '" & Me.txtUsername.Value  & "'") Then
      Linq ;0)>

      Comment

      • AccessBeetle
        New Member
        • Jul 2009
        • 111

        #4
        Thanks that worked.!!
        One more situation: how do we specify the criteria if we are matching the username that is on another form's textbox?
        Something like this
        If Me.txtSecurityC ode.Value = DLookup("[SecurityCode]", "RadioLog_tblVa lUsers", "[UserName] =" & Forms!frmLogin! txtUsername) Then

        Is this correct?

        Comment

        Working...