Option Compare Database
Option Explicit
Function DisplayMenu(UserId As Variant)
''On Error GoTo err_display_menu
' at this stage the userId and access level has been checked
Dim AccessLevel As Integer
Dim FinishDate As Date
Dim PortSyd As String
Dim ValidUser As Integer
Dim CheckUser As Integer
Dim PasswordPeriod As Date
Dim CheckPassword As String
Dim strmsg As String
Dim strSQL As String, sFilter As String
ValidUser = 2
' *****************************************************************************************************************
' validate user_id
' *****************************************************************************************************************
strSQL = "SELECT [initials],[password],[access_level],[password_date] FROM tbl_users " _
& "WHERE initials=" & Forms!Frm_Login!Initials
''strSQL = "SELECT [personeelsnummer],[passwords] FROM tbl_users WHERE personeelsnummer=" & PersNr
Dim tmp
''tmp = InputBox("", "", strSQL)
With CurrentDb.OpenRecordset(strSQL)
If .RecordCount = 1 Then
ValidUser = 2
If .Fields("password") = Forms!Frm_Login!Password Then
AccessLevel = .Fields("Access_Level").Value
PasswordPeriod = CDate(.Fields("password_date").Value)
Else
ValidUser = 1
AccessLevel = 4
End If
Else
ValidUser = 0
End If
.Close
End With
' *****************************************************************************************************************
' validate access_level
' *****************************************************************************************************************
Select Case ValidUser
Case 0, 1
strmsg = " Access Denied" & vbCrLf & " Contact your Administrator if the problem persists. "
MsgBox strmsg, vbInformation, "INVALID USER ID or PASSWORD"
' DoCmd.Quit
Case 2
Select Case AccessLevel
Case 1 ' lv1 menu
' validate password expiry
If PasswordPeriod < Date - 30 Then
strmsg = "Your password has expired. You must change your password"
MsgBox strmsg, vbInformation, "Expired Password"
DoCmd.OpenForm "Frm_change_password", acNormal
Else
DoCmd.Close acForm, "Frm_Login"
DoCmd.OpenForm "Frm_switchboard_lv1"
End If
Case 2 ' lv2 menu
' validate password expiry
If PasswordPeriod < Date - 30 Then
strmsg = "Your password has expired. You must change your password"
MsgBox strmsg, vbInformation, "Expired Password"
DoCmd.OpenForm "Frm_change_password", acNormal
Else
DoCmd.Close acForm, "Frm_Login"
DoCmd.OpenForm "Frm_switchboard_lv2"
Case 3 ' lv3 menu
' validate password expiry
If PasswordPeriod < Date - 30 Then
strmsg = "Your password has expired. You must change your password"
MsgBox strmsg, vbInformation, "Expired Password"
DoCmd.OpenForm "Frm_change_password", acNormal
Else
DoCmd.Close acForm, "Frm_Login"
DoCmd.OpenForm "Frm_switchboard_lv3"
End If
Case Else
strmsg = " Access Denied" & vbCrLf & "Contact your Administrator if the problem persists."
MsgBox strmsg, vbInformation, "INVALID USER ID or PASSWORD"
End Select
Case Else
End Select
''' close main form frm_main
'' DoCmd.Close acForm, "frm_main"
exit_display_menu:
Exit Function
err_display_menu:
MsgBox Err.Description
Resume exit_display_menu
End Function
Sub Display_Menu()
On Error GoTo err_display_menu
' at this stage the userId and access level has been checked
Dim access_level As Integer
Dim Finish_Date As Date
Dim Port_Syd As String
Dim Valid_User As Integer
Dim Check_User As Integer
Dim Password_Period As Date
Dim Check_Password As String
Dim strmsg As String
Valid_User = 2
' **********************************************
' validate user_id
' **********************************************
Check_User = DCount("[UserID]", "Tbl_users", "Initials=" & Forms!Frm_Login!Initials & "")
If Check_User = 1 Then
Valid_User = 2
Else
Valid_User = 0
End If
' **********************************************
' validate password
' **********************************************
If Valid_User = 2 Then
Check_Password = DLookup("[password]", "Tbl_users", "Initials=" & Forms!Frm_Login!Initials & "")
If UCase(Check_Password) = UCase(Forms!Frm_Login!Password) Then
Valid_User = 2
Else
Valid_User = 1
End If
End If
' **********************************************
' validate access_level
' **********************************************
If Valid_User = 2 Then
access_level = DLookup("[access_level]", "Tbl_users", "Initials=" & Forms!Frm_Login!Initials & "")
End If
Select Case Valid_User
Case 0, 1
strmsg = " Access Denied" & vbCrLf & " Contact your Administrator if the problem persists. "
MsgBox strmsg, vbInformation, "INVALID USER ID or PASSWORD"
' DoCmd.Quit
Case 2
Select Case access_level
Case 1 ' level1 menu
' validate password expiry
Password_Period = DLookup("[password_date]", "Tbl_users", "initials=" & Forms!Frm_Login!Initials & "")
If Password_Period < Date - 30 Then
strmsg = " Your password has expired. You must change your password"
MsgBox strmsg, vbInformation, "Expired Password"
DoCmd.OpenForm "Frm_change_password", acNormal
Else
DoCmd.OpenForm "Frm_switchboard_lv1"
End If
Case 2 ' level2 menu
' validate password expiry
Password_Period = DLookup("[password_date]", "tbl_users", "personeelsnummer=" & Forms!Frm_Login!Initials & "")
If Password_Period < Date - 30 Then
strmsg = " Your password has expired. You must change your password"
MsgBox strmsg, vbInformation, "Expired Password"
DoCmd.OpenForm "Frm_change_password", acNormal
Else
DoCmd.OpenForm "Frm_switchboard_lv2"
End If
Case 3 ' level3 menu
' validate password expiry
Password_Period = DLookup("[password_date]", "Tbl_users", "personeelsnummer=" & Forms!Frm_Login!Initials & "")
If Password_Period < Date - 30 Then
strmsg = " Your password has expired. You must change your password"
MsgBox strmsg, vbInformation, "Expired Password"
DoCmd.OpenForm "Frm_change_password", acNormal
Else
DoCmd.OpenForm "Frm_switchboard_lv3"
End If
Case Else
strmsg = " Access Denied" & vbCrLf & " Contact your Administrator if the problem persists. "
MsgBox strmsg, vbInformation, "INVALID USER ID or PASSWORD"
End Select
End Select
' close main form frm_main
DoCmd.Close acForm, "frm_Login"
exit_display_menu:
Exit Sub
err_display_menu:
MsgBox Err.Description
Resume exit_display_menu
End Sub