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
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.
Comment