By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,761 Members | 1,879 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,761 IT Pros & Developers. It's quick & easy.

MSAccess 2010 Mulitple Login Attempt Failure

benchpolo
100+
P: 142
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdProcess_Click()
  2.     DoCmd.SetWarnings False
  3.  
  4.     Dim rs As ADODB.Recordset
  5.     Dim rsv As ADODB.Recordset
  6.     Dim cnCurrent As ADODB.Connection
  7.     Dim strSql As String    'verify the userid and password
  8.  
  9.     Set cnCurrent = CurrentProject.Connection
  10.     Set rs = New ADODB.Recordset
  11.  
  12.     strSql = "SELECT * FROM dbo_LogInInfo " & _
  13.              "WHERE user_id = '" & user_id & "' " & _
  14.              "AND secretpass = '" & secretpass & "'"
  15.  
  16.     Set rs = cnCurrent.Execute(strSql)
  17.  
  18.     If rs.EOF Or rs.BOF Then
  19.         MsgBox "Invalid login.  Please try again!"
  20.         Call LoginAttempts
  21.         user_id.SetFocus
  22.         user_id.Text = ""
  23.         secretpass.SetFocus
  24.         secretpass.Text = ""
  25.         user_id.SetFocus
  26.     Else
  27.         gUsername = rs!username
  28.         gUserId = rs!user_id
  29.         gPassword = rs!secretpass
  30.         gAccessLevel = rs!accesslevel
  31.         Call TrackStaff
  32.         DoCmd.OpenForm "frmMain", acNormal
  33.         DoCmd.Close acForm, "frmLogin"
  34.     End If
  35.     cnCurrent.Close
  36.     Set cnCurrent = Nothing    
  37. End Sub
  38.  
  39. Private Sub LoginAttempts()
  40.     Dim rst1 As ADODB.Recordset
  41.     Dim db As Database
  42.     Dim cnt As Integer
  43.  
  44.     Set rst1 = db.OpenRecordset("dbo_tblFailedAttempts", dbOpenDynaset)
  45.  
  46.     With rst1
  47.         .AddNew
  48.         ![computer_login] = Me.user_id
  49.         .Update
  50.     End With
  51.  
  52.     MsgBox "You entered the wrong User Name or Password." & Chr(13) & _
  53.         "Please enter the correct User Name and Password or " & Chr(13) & _
  54.         "contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied"
  55.  
  56.     cnt = cnt + 1
  57.  
  58.     If cnt = 3 Then
  59.         MsgBox "Access Violation Program Will Now Close!", , "Vilation Detected"
  60.         DoCmd.Close acForm, "frmLogin", acSaveYes
  61.     End If
  62. End Sub
  63.  
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.OpenRecordset("dbo_tblFailedAttempts", dbOpenDynaset), and rst1 is declared. Please advice.

Thanks.
Jul 23 '12 #1
Share this Question
Share on Google+
6 Replies


dsatino
100+
P: 393
You didn't set the 'db' variable to anything so it doesn't have a database object to open the recordset from.
Jul 23 '12 #2

Rabbit
Expert Mod 10K+
P: 12,366
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.
Jul 23 '12 #3

benchpolo
100+
P: 142
So you are saying that I shouln't do a Dim db As Database or Set rst1 = db.OpenRecordset("dbo_tblFailedAttempts", dbOpenDynaset)
Can you please provide a updated line of code.
Jul 23 '12 #4

benchpolo
100+
P: 142
This is where i got the code, and I just tweaked it.
http://www.ehow.com/how_7518071_prev...-attempts.html
Jul 23 '12 #5

dsatino
100+
P: 393
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.
Jul 23 '12 #6

Seth Schrock
Expert 2.5K+
P: 2,941
I believe the following is what you need:

Expand|Select|Wrap|Line Numbers
  1. Set db = CurrentDb
Put it in line 43.

This sets the db variable that you declared using the
Expand|Select|Wrap|Line Numbers
  1. Dim db as Database
code. Once you set the declared variable, Access will know what db is.
Jul 24 '12 #7

Post your reply

Sign in to post your reply or Sign up for a free account.