I am fairly new to the VBA coding in access and would like some help with a log on form I am using for my database. I have the following code that works fine for opening the form I have mentioned but would like the code to break it out a little further by checking to see if the admin box (yes/no)is checked and open a different form depending on yes or no. Here is the code I have presently:
'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
If Me.txtPassword.Value = DLookup("Password", "Technicians", "[ID]=" & Me.cboEmployee.Value) Then
MyID = Me.cboEmployee.Value
'Close logon form and open splash screen
DoCmd.Close acForm, "frmStartUp", acSaveNo
DoCmd.OpenForm "frmAdm"
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtPassword.SetFocus
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 your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub
I use a Log in Box and a Password box for inputting the data and I have an Admin field (yes/No) in my "Technicians" table. If yes for Admin - open frmAdm and if No - open frmUser.
Can anyone help?
'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
If Me.txtPassword.Value = DLookup("Password", "Technicians", "[ID]=" & Me.cboEmployee.Value) Then
MyID = Me.cboEmployee.Value
'Close logon form and open splash screen
DoCmd.Close acForm, "frmStartUp", acSaveNo
DoCmd.OpenForm "frmAdm"
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtPassword.SetFocus
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 your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub
I use a Log in Box and a Password box for inputting the data and I have an Admin field (yes/No) in my "Technicians" table. If yes for Admin - open frmAdm and if No - open frmUser.
Can anyone help?
