'****************************
'* code for module basMyEmpID
'****************************
Option Explicit
Option Compare Database
Public lngMyEmpID As Long
'****************************
'* code for Form_frmLogon
'****************************
Option Explicit
Option Compare Database
Private intLogonAttempts As Integer
Private Sub Form_Open(Cancel As Integer)
'On open set focus to combo box
Me.cboEmployee.SetFocus
intLogonAttempts = 0
End Sub
Private Sub cboEmployee_AfterUpdate()
'After selecting user name set focus to password field
Me.txtPassword.SetFocus
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 "User Name is a required field.", 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 "Password is a required field.", 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("strEmpPassword", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value) Then
lngMyEmpID = Me.cboEmployee.Value
'Close logon form and open splash screen (could be Switchboard or another form instead)
DoCmd.Close acForm, "frmLogon", acSaveNo 'substitute correct name if using
'form other than frmLogon in the example.
DoCmd.OpenForm "frmSplash_Screen" 'substitute correct name if using switch
'board or other form.
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, "Access to Access is Restricted!"
Application.Quit
End If
End Sub
'****************************
'* code for Form_frmSplash_Screen
'****************************
Option Explicit
Option Compare Database
'The code in this form will be deleted if the form is deleted and a
'switchboard style form or another form is used instead of the splash
'screen.
Private Sub Form_Close()
DoCmd.SelectObject acTable, "tblEmployees", True
End Sub
Private Sub Form_Timer()
'When the Timer Interval is achieved, this form closes
DoCmd.Close
End Sub
|