R
ryguy7272
I received some great help here and I am trying to do a few more things now.
I have the Access 2007 Bible, which is great, but is doesn’t seem to answer
my questions so I have returned here once again. Just yesterday I got some
help with the code below (with modifications…which causes it to not work):
'Private Sub cboEmployee_BeforeUpdate(Cancel As Integer)
Private Sub cboEmployee_AfterUpdate()
'After selecting user name set focus to password field
Me.txtPassword.SetFocus
End Sub
'End Sub
Private Sub cmdLogin_Click()
'Check to see if data is entered into the UserName combo box
If IsNull(Me.cboEmployee) 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.txtPassword) 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 tblEmployees to see if this
'matches value chosen in combo box
'Remeber: Login is a text field and that you really want to get the
'Password returned by Dlookup. You need to surround the value of
'CboEmployee with quote marks so it is treated as a string.
If Me.txtPassword.Value = DLookup("Password", "tblLogin", _
"[Login]=""" & "[Level]=Director" & Me.cboEmployee.Value & """") Then
lngMyEmpID = Me.cboEmployee.Value
'Close logon form and open splash screen
DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "frmDirector"
If Me.txtPassword.Value = DLookup("Password", "tblLogin", _
"[Login]=""" & "[Level]=RVP" & Me.cboEmployee.Value & """") Then
lngMyEmpID = Me.cboEmployee.Value
'Close logon form and open splash screen
DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "frmRVP"
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
"Invalid Entry!"
Me.txtPassword.SetFocus
End If
End If
'If User Enters incorrect password 3 times database will shutdown
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database.Please contact
admin.", _
vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub
I am now trying to figure out how to modify this slightly to check the Table
tblLogin for the individual’s Login name and the person’s password, and then
if the individual is a ‘Director’ open one Form (frm Director) and if the
individual is an ‘RVP’ open another Form (frmRVP). The individual’s level
comes from a field named ‘Level’. The code, as it is now, doesn’t do
anything; not error, just nothing.
I’d really appreciate any help on this.
Thanks,
Ryan---
I have the Access 2007 Bible, which is great, but is doesn’t seem to answer
my questions so I have returned here once again. Just yesterday I got some
help with the code below (with modifications…which causes it to not work):
'Private Sub cboEmployee_BeforeUpdate(Cancel As Integer)
Private Sub cboEmployee_AfterUpdate()
'After selecting user name set focus to password field
Me.txtPassword.SetFocus
End Sub
'End Sub
Private Sub cmdLogin_Click()
'Check to see if data is entered into the UserName combo box
If IsNull(Me.cboEmployee) 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.txtPassword) 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 tblEmployees to see if this
'matches value chosen in combo box
'Remeber: Login is a text field and that you really want to get the
'Password returned by Dlookup. You need to surround the value of
'CboEmployee with quote marks so it is treated as a string.
If Me.txtPassword.Value = DLookup("Password", "tblLogin", _
"[Login]=""" & "[Level]=Director" & Me.cboEmployee.Value & """") Then
lngMyEmpID = Me.cboEmployee.Value
'Close logon form and open splash screen
DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "frmDirector"
If Me.txtPassword.Value = DLookup("Password", "tblLogin", _
"[Login]=""" & "[Level]=RVP" & Me.cboEmployee.Value & """") Then
lngMyEmpID = Me.cboEmployee.Value
'Close logon form and open splash screen
DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "frmRVP"
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
"Invalid Entry!"
Me.txtPassword.SetFocus
End If
End If
'If User Enters incorrect password 3 times database will shutdown
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database.Please contact
admin.", _
vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub
I am now trying to figure out how to modify this slightly to check the Table
tblLogin for the individual’s Login name and the person’s password, and then
if the individual is a ‘Director’ open one Form (frm Director) and if the
individual is an ‘RVP’ open another Form (frmRVP). The individual’s level
comes from a field named ‘Level’. The code, as it is now, doesn’t do
anything; not error, just nothing.
I’d really appreciate any help on this.
Thanks,
Ryan---