Sie sind auf Seite 1von 4

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

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 "frmSplash_Screen"

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 admin.", _
vbCritical, "Restricted Access!"
Application.Quit
End If

End Sub
Option Compare Database

Private Sub Command1_Click()

Dim User As String

Dim UserLevel As Integer

Dim TempPass As String

Dim ID As Integer

Dim UserName As String

Dim TempID As String

If IsNull(Me.txtUserName) Then

MsgBox "Please enter UserName", vbInformation, "Username required"

Me.txtUserName.SetFocus

ElseIf IsNull(Me.txtPassword) Then

MsgBox "Please enter Password", vbInformation, "Password required"

Me.txtPassword.SetFocus

Else

If (IsNull(DLookup("UserLogin", "tblUser", "UserLogin = '" &


Me.txtUserName.Value & "' And UserPassword = '" & Me.txtPassword.Value &
"'"))) Then

MsgBox "Invalid Username or Password!"

Else

TempID = Me.txtUserName.Value
UserName = DLookup("[UserName]", "tblUser", "[UserLogin] = '" &
Me.txtUserName.Value & "'")

UserLevel = DLookup("[UserType]", "tblUser", "[UserLogin] = '" &


Me.txtUserName.Value & "'")

TempPass = DLookup("[UserPassword]", "tblUser", "[UserLogin] = '" &


Me.txtUserName.Value & "'")

UserLogin = DLookup("[UserLogin]", "tblUser", "[UserLogin] = '" &


Me.txtUserName.Value & "'")

DoCmd.Close

If (TempPass = "password") Then

MsgBox "Please change Password", vbInformation, "New password required"

DoCmd.OpenForm "frmUserinfo", , , "[UserLogin] = " & UserLogin

Else

'open different form according to user level

If UserLevel = 1 Then ' for admin

DoCmd.OpenForm "Admin Form"

Else

DoCmd.OpenForm "Navigation Form"

End If

End If

End If

End If

End Sub
Private Sub Form_Load()

Me.txtUserName.SetFocus

End Sub

Das könnte Ihnen auch gefallen