MSAccess 2010 Mulitple Login Attempt Failure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • benchpolo
    New Member
    • Sep 2007
    • 142

    MSAccess 2010 Mulitple Login Attempt Failure

    Code:
    Private Sub cmdProcess_Click()
        DoCmd.SetWarnings False
        
        Dim rs As ADODB.Recordset
        Dim rsv As ADODB.Recordset
        Dim cnCurrent As ADODB.Connection
        Dim strSql As String    'verify the userid and password
        
        Set cnCurrent = CurrentProject.Connection
        Set rs = New ADODB.Recordset
                     
        strSql = "SELECT * FROM dbo_LogInInfo " & _
                 "WHERE user_id = '" & user_id & "' " & _
                 "AND secretpass = '" & secretpass & "'"
        
        Set rs = cnCurrent.Execute(strSql)
        
        If rs.EOF Or rs.BOF Then
            MsgBox "Invalid login.  Please try again!"
            Call LoginAttempts
            user_id.SetFocus
            user_id.Text = ""
            secretpass.SetFocus
            secretpass.Text = ""
            user_id.SetFocus
        Else
            gUsername = rs!username
            gUserId = rs!user_id
            gPassword = rs!secretpass
            gAccessLevel = rs!accesslevel
            Call TrackStaff
            DoCmd.OpenForm "frmMain", acNormal
            DoCmd.Close acForm, "frmLogin"
        End If
        cnCurrent.Close
        Set cnCurrent = Nothing    
    End Sub
    
    Private Sub LoginAttempts()
        Dim rst1 As ADODB.Recordset
        Dim db As Database
        Dim cnt As Integer
          
        Set rst1 = db.OpenRecordset("dbo_tblFailedAttempts", dbOpenDynaset)
       
        With rst1
            .AddNew
            ![computer_login] = Me.user_id
            .Update
        End With
            
        MsgBox "You entered the wrong User Name or Password." & Chr(13) & _
            "Please enter the correct User Name and Password or " & Chr(13) & _
            "contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied"
           
        cnt = cnt + 1
        
        If cnt = 3 Then
            MsgBox "Access Violation Program Will Now Close!", , "Vilation Detected"
            DoCmd.Close acForm, "frmLogin", acSaveYes
        End If
    End Sub
    ISSUE
    I am trying to validate the number of login attempt failure in my database (see code above), but after clicking "LOGIN" button the userid/password is validated, but i am getting an error Run-Time error 91: Object variable or With Block variable not set in the code line Set rst1 = db.OpenRecordse t("dbo_tblFaile dAttempts", dbOpenDynaset), and rst1 is declared. Please advice.

    Thanks.
  • dsatino
    Contributor
    • May 2010
    • 393

    #2
    You didn't set the 'db' variable to anything so it doesn't have a database object to open the recordset from.

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      Your db variable is not set. There's a difference between set and declare. You've declared your db variable. But it's not set to anything. So there's no database for it to use.

      Comment

      • benchpolo
        New Member
        • Sep 2007
        • 142

        #4
        So you are saying that I shouln't do a Dim db As Database or Set rst1 = db.OpenRecordse t("dbo_tblFaile dAttempts", dbOpenDynaset)
        Can you please provide a updated line of code.

        Comment

        • benchpolo
          New Member
          • Sep 2007
          • 142

          #5
          This is where i got the code, and I just tweaked it.

          Comment

          • dsatino
            Contributor
            • May 2010
            • 393

            #6
            No. What we are saying is that a recordset object can only be opened within a database object and you haven't set a database object which is why your recordset object isn't opening.

            Comment

            • Seth Schrock
              Recognized Expert Specialist
              • Dec 2010
              • 2965

              #7
              I believe the following is what you need:

              Code:
              Set db = CurrentDb
              Put it in line 43.

              This sets the db variable that you declared using the
              Code:
              Dim db as Database
              code. Once you set the declared variable, Access will know what db is.

              Comment

              Working...