To clarify I am adding the whole code:
When the user log's into my application: they click on a button object after
inputting a user name and password:
Private Sub cmdOK_Click()
On Error GoTo Err_cmdOK_Click
' Validate User ID and Password and then display menu items
display_menu
Exit_cmdOK_Click:
Exit Sub
Err_cmdOK_Click:
MsgBox Err.Description
Resume Exit_cmdOK_Click
End Sub
display_Menu is sub module I created. The code is:
Option Compare Database
Option Explicit
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("[user_id]", "tbl_users", "user_id=forms!frm_main!
user_id")
If check_user = 1 Then
valid_user = 2
Else
valid_user = 0
End If
' **********************************************
' validate password
' **********************************************
If valid_user = 2 Then
check_password = DLookup("[passwords]", "tbl_users", "user_id=forms!
frm_main!user_id")
If UCase(check_password) = UCase(Forms!frm_main!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", "user_id=forms!
frm_main!user_id")
End If
Select Case valid_user
Case 0, 1
strmsg = " Access Denied" & _
vbCrLf & " Contact your IT Specialist 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", "user_id = forms!frm_main!user_id")
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.Close
DoCmd.OpenForm "frmSwitchBoard"
End If
Case 2 ' level2 menu
' validate password expiry
password_period = DLookup("[password_date]",
"tbl_users", "user_id = forms!frm_main!user_id")
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.Close
DoCmd.OpenForm "frmMainData"
ONCE "frmMainData" (A FORM) Opens with no problem, however, the form contains
a button object that I don't want a user with LEVEL 2 access to see. The
button control name is btntomainform
When I enter:
Me.btnmainform.visible=false after: DoCmd.OpenForm"frmMainData" as
illustrated above and run my application by having a user with level 2 access
log in, I get an error message: COMPILE ERROR INVALID USE OF ME KEYWORD ???
?
just make sure the the commnd button does not have the focus and use
[quoted text clipped - 12 lines]