MS Access "run-time Error 2001, You canceled the previous operation"?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mufc4life
    New Member
    • Mar 2010
    • 3

    MS Access "run-time Error 2001, You canceled the previous operation"?

    Hi, actually I'm creating a database for some coursework at school. It's basically about a booking system and how I book hardware in and out of the school for students who need the hardware. I've tried to create a login screen, so that teachers can log in and out the system. I've got one table that is involved in this code, which is the 'tblTechnicianF ile'. That's the table that contains the technician's ID and the password as well. The following links are print screens of my tblTechnicianFi le and my actual form, which is my login screen.
    http://i209.photobucke t.com/albums/bb68/ud1992/ms%20access%20p rob/Untitled-2.png
    http://i209.photobucke t.com/albums/bb68/ud1992/ms%20access%20p rob/Untitled-4.png

    The problem is that it is supposed to send me to another screen when the password is right, but it keeps giving me the "run-time error..." screen whether I put in the right password or not.

    This is the all the codes that I have got entered, something must be wrong with it, but I cannot spot it. Help.



    Option Compare Database

    Private Sub cboEmployee_Aft erUpdate()

    Me.txtPassword. SetFocus

    End Sub


    Private Sub cmdLogin_Click( )

    'Check to see if data is entered into the UserName combo box

    If IsNull(Me.cboEm ployee) Or Me.cboEmployee = "" Then
    MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
    Me.cboEmployee. SetFocus
    Exit Sub
    End If

    'Check to see if data is entered into the password box

    If IsNull(Me.txtPa ssword) 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 login to see if this
    'matches value chosen in combo box

    If Me.txtPassword. Value = DLookup("Passwo rd", "tblTechnicianF ile", _
    "[Technician ID]=" & Me.cboEmployee. Value) Then

    lngMyEmpID = Me.cboEmployee. Value

    'Close logon form and open splash screen

    DoCmd.Close acForm, "login screen", acSaveNo
    DoCmd.OpenForm "Switchboar d"

    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

    intLogonAttempt s = intLogonAttempt s + 1
    If intLogonAttempt s > 3 Then
    MsgBox "You do not have access to this database.Please contact admin.", _
    vbCritical, "Restricted Access!"
    Application.Qui t
    End If

    End Sub

    ---------------------------------------------------------------------------------------------------------------
    Additional Details
    if anyone wants to contact me to get more details about this problem or anything like that, my msn is: uddeshd@yahoo.c o.uk
  • MikeTheBike
    Recognized Expert Contributor
    • Jun 2007
    • 640

    #2
    Hi

    Just one suggestion:-

    Try opening the 'Switchboard' BEFORE you close the 'Login Screen'

    ??


    MTB

    Comment

    • mufc4life
      New Member
      • Mar 2010
      • 3

      #3
      erm, I'm not really sure what you mean by that.. are you telling me to edit the code, or open the switchboard form?

      If you mean edit the code, can you give me the new code please, as I am not really good with coding.

      I found those coding instructions on how to make a login form from this website: http://www.databasedev.co.uk/login.html

      but apparently that code only works if the ID is an autonumber field, and mine is a text one. That's what is causing the problem, as it worked fine for my friend, because he had his TechnicianID field as an autonumber.

      Thanks.

      Comment

      • MikeTheBike
        Recognized Expert Contributor
        • Jun 2007
        • 640

        #4
        Hi

        OK so you have a text user ID (Why?), then I suggest changing this
        Code:
        If Me.txtPassword.Value = DLookup("Password", "tblTechnicianFile", _
        "[Technician ID]=" & Me.cboEmployee.Value) Then
        to this
        Code:
        If Me.txtPassword.Value = DLookup("Password", "tblTechnicianFile", _
        "[Technician ID]='" & Me.cboEmployee.Value & "'") Then
        Note th apostrophies enclosing Me.cboEmployee. Value

        These delimiters are required for all text variable in this situation so the program knows where the variable text starts and ends within the program text.

        HTH


        MTB

        Comment

        • mufc4life
          New Member
          • Mar 2010
          • 3

          #5
          thanks a lot mate, it worked. However, now the problem is with the last code

          'If User Enters incorrect password 3 times database will shutdown

          intLogonAttempt s = intLogonAttempt s + 1
          If intLogonAttempt s > 3 Then
          MsgBox "You do not have access to this database.Please contact admin.", _
          vbCritical, "Restricted Access!"
          Application.Qui t
          End If
          This is the code that checks if an incorrect password has been entered more than 3 times.. I tried entering a wrong password over 3 times, but didn't work, would apreciate if you could help me on this bit as well? Thanks again.

          Comment

          • MikeTheBike
            Recognized Expert Contributor
            • Jun 2007
            • 640

            #6
            Hi

            Two things
            1) You do not say what actually happens
            2) Where is the variable 'intLogonAttemp ts' declared?

            To start I would temperarily add this line

            MsgBox intLogonAttempt s

            immediatly after this line

            intLogonAttempt s = intLogonAttempt s + 1

            and see if it starts at 1 and index with each incorrct password.

            'intLogonAttemp ts' should be declared at the top of the form 'login screen' code module ie.

            Dim intLogonAttempt s as Integer


            MTB

            Comment

            Working...