Here is a neater way of writing the same thing. See how the logic flow is more obvious without all the IF ..Else.. ElseIF constructs.
Code:
Private Sub Enter_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.txtLoginID) Then
MsgBox "Please enter UserName", vbInformation, "Username required"
Me.txtLoginID.SetFocus
Exit Sub
End If
If IsNull(Me.txtPassword) Then
MsgBox "Please enter Password", vbInformation, "Password required"
Me.txtPassword.SetFocus
Exit Sub
End If
If (IsNull(DLookup("LoginID", "tblEmployees", "LoginID = '" & Me.txtLoginID & "' And Password = '" & Me.txtPassword & "'"))) Then
MsgBox "Invalid Username or Password!"
Exit Sub
End If
TempID = Me.txtLoginID
UserName = DLookup("[UserName]", "tblEmployees", "[LoginID] = '" & Me.txtLoginID & "'")
UserSecurity = DLookup("[UserSecurity]", "tblEmployees", "[LoginID] = '" & Me.txtLoginID & "'")
TempPass = DLookup("[Password]", "tblEmployees", "[LoginID] = '" & Me.txtLoginID & "'")
LoginID = DLookup("[LoginID]", "tblEmployees", "[LoginID] = '" & Me.txtLoginID & "'")
DoCmd.Close
If (TempPass = "password") Then
MsgBox "Please change Password", vbInformation, "New password required"
DoCmd.OpenForm "frmUserinfo", , , "[LoginID] = " & LoginID
Else
'open different form according to user level
If UserLevel = 1 Then ' for Director
DoCmd.OpenForm "CabinetTech Form"
Else
DoCmd.OpenForm "JobProgress"
End If
End If
End Sub
Also indenting the code makes it much easier to see where the If constructs code is being followed.