Here is the code as it is now:
Option Compare Database
Private Sub Auto_Title0_Click()
'After selecting username set focus to password field
Me.txtPassword.SetFocus
End Sub
Private Sub cboCurrentUser_AfterUpdate()
'After selecting User name set focus to password field
Me.txtPassword.SetFocus
End Sub
Private Sub cboCurrentUser_BeforeUpdate(Cancel As Integer)
End Sub
Private Sub cmdLogin_Click()
'Check to see if data is entered into the UserName combo box
If IsNull(Me.cboCurrentUser) Or Me.cboCurrentUser = "" Then
MsgBox "You must enter your User Name.", vbOKOnly, "Required Data"
Me.cboCurrentUser.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 your password.", vbOKOnly, "Required data"
Me.txtPassword.SetFocus
Exit Sub
End If
'Check Value of password in tblUsers to see if this
'matches value chosen in combo box
Dim UserID As String
If Me.txtPassword.Value = DLookup("strUserPswd", "Users", _
"[UserID]=" & Me.cboCurrentUser.Value) Then
UserID = Me.cboCurrentUser.Value
'Close login form and open Instructor Input form
DoCmd.Close acForm, "Logon", acSaveNo
DoCmd.OpenForm "Instructor Input"
Else
MsgBox "Invalid Password. Please Try Again", vbOKOnly, _
"Invalid Entry!"
Me.txtPassword.SetFocus
End If
'If User enters incorrct password 3 times the database will shut down
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database. Contact the database
Administrator.", vbCritical, _
"Restricted Access!"
Application.Quit
End If
End Sub
Private Sub cmdLogin_DblClick(Cancel As Integer)
End Sub
Private Sub Detail_Click()
End Sub
Private Sub Form_AfterUpdate()
End Sub
Private Sub Form_Click()
Dim UserID As String 'this is the part that was added thanks to AccessVandal
End Sub
Private Sub Form_Load()
End Sub
Private Sub Form_LostFocus()
End Sub
Private Sub Form_OnConnect()
End Sub
Private Sub Form_Open(Cancel As Integer)
End Sub
Private Sub Form_Unload(Cancel As Integer)
End Sub
Private Sub Form_ViewChange(ByVal Reason As Long)
End Sub
Billiam said:
Thank you again for your advice. Declaring the variable in the onclick event
did not work on its own. Placing
Dim UserID as String
in the procedure where I was getting the debug error did work. I will
repaste all code in case anyone is interested and trying to learn, as I am!
My question is, were both of these changes required, or was it soley
defining the UserID variable, and regardless of this, WHY was the current
version and 52 incremental backups retroactively affected?
One more thing, when I click on a table to work on it, the table opens, but
there is no tab in the top left corner (to close, design view, form view,
etc) Could this also point to what it is i have screwed up playing around in
the Access Options? Can I reset the Access Options to the default?
MANY THANKS for getting this wirking at
least!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
You're the best!
Billiam
AccessVandal via AccessMonster.com said:
Billiam,
Sorry, but I don't see where is the declared variable "UserID". Second I
don't see that you have any error trapping.
You might want to declare the variable in the onclick event...like.
Dim UserID as String
Now the login form is generating the following error if you don't tab
throught the three form fields first:
Run time error 3164. Field cannot be updated.
It highlights the following from the login code: UserID =
Me.cboCurrentUser.Value
Here is the code:
Option Compare Database
Private Sub Auto_Title0_Click()
'After selecting username set focus to password field
Me.txtPassword.SetFocus
End Sub
Private Sub cboCurrentUser_AfterUpdate()
'After selecting User name set focus to password field
Me.txtPassword.SetFocus
End Sub
Private Sub cboCurrentUser_BeforeUpdate(Cancel As Integer)
End Sub
Private Sub cmdLogin_Click()
'Check to see if data is entered into the UserName combo box
If IsNull(Me.cboCurrentUser) Or Me.cboCurrentUser = "" Then
MsgBox "You must enter your User Name.", vbOKOnly, "Required Data"
Me.cboCurrentUser.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 your password.", vbOKOnly, "Required data"
Me.txtPassword.SetFocus
Exit Sub
End If
'Check Value of password in tblUsers to see if this
'matches value chosen in combo box
If Me.txtPassword.Value = DLookup("strUserPswd", "Users", _
"[UserID]=" & Me.cboCurrentUser.Value) Then
UserID = Me.cboCurrentUser.Value (This is the line indicated from
debugger)
'Close login form and open Instructor Input form
DoCmd.Close acForm, "Logon", acSaveNo
DoCmd.OpenForm "Instructor Input"
Else
MsgBox "Invalid Password. Please Try Again", vbOKOnly, _
"Invalid Entry!"
Me.txtPassword.SetFocus
End If
'If User enters incorrct password 3 times the database will shut down
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database. Contact the database
Administrator.", vbCritical, _
"Restricted Access!"
Application.Quit
End If
End Sub
Private Sub cmdLogin_DblClick(Cancel As Integer)
End Sub
Private Sub Detail_Click()
End Sub
Private Sub Form_AfterUpdate()
End Sub
Private Sub Form_Load()
End Sub
Private Sub Form_LostFocus()
End Sub
Private Sub Form_OnConnect()
End Sub
Private Sub Form_Open(Cancel As Integer)
End Sub
Private Sub Form_Unload(Cancel As Integer)
End Sub
Private Sub Form_ViewChange(ByVal Reason As Long)
End Sub
Also, there are no tabs available on my tables when they are selected, so no
save option, close option, design view etc.
Thanks for any help,
Billiam