Login in Access 2007
Posted on 2011-10-17
I need some VBA coding to handle a two different kinds of users entering passwords in. I have my code for an administration user when they enter password in, but I nned to have some coidng where when an ordinary user enterss their password a different menu form opens up.
Private Sub Form_Open(Cancel As Integer)
'On open set focus to combo box
Private Sub cboEmployee_AfterUpdate()
'After selecting user name set focus to password field
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"
'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"
'Check value of password in tblEmployees to see if this matches value chosen in combo box
If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value) Then
lngMyEmpID = Me.cboEmployee.Value
'Close logon form and open splash screen
DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "Startup Screen"
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
I have an Employee table that holds the User
with these fields: lngEmpId, StrEmpName, StrEmpPassword, and StrAccess.