K
Keiron via AccessMonster.com
Hi I have a main page that loads after using the login page to enter username
and password, when the main page loads i want the controls on the main page
to be hidding if the user is not a manager or admin. I have the following
code and it works if i remove the ElseIF part of the code that looks up if
they are a manager.
any help would be greatly appreciated.
Cheers
Keiron
Private Sub Form_Load()
On Error GoTo Err_Form_Load
'Put the username in the text box
WorkerName = Forms![login]![txtuser]
'Close the login form
DoCmd.Close acForm, "Login"
'Get their username
'WorkerName = Forms![frm_main]![WorkerName]
'See if they are admin or have admin rights
If WorkerName = "admin" Or DLookup("admin", "tbl_worker", "WorkerName = '" &
WorkerName & "'") = "Yes" Then
admin.Visible = True
Managers.Visible = True
ManagersReports.Visible = True
ElseIf DLookup("Manager", "tbl_worker", "WorkerName = '" & WorkerName & "'")
= "Yes" Then
Managers.Visible = True
ManagersReports.Visible = True
Else
admin.Visible = False
Managers.Visible = False
ManagersReports.Visible = False
End If
DoCmd.Maximize
Exit_Form_Load:
Exit Sub
Err_Form_Load:
MsgBox Err.Description
DoCmd.OpenForm "Login"
DoCmd.Close acForm, "frm_main"
Resume Exit_Form_Load
End Sub
and password, when the main page loads i want the controls on the main page
to be hidding if the user is not a manager or admin. I have the following
code and it works if i remove the ElseIF part of the code that looks up if
they are a manager.
any help would be greatly appreciated.
Cheers
Keiron
Private Sub Form_Load()
On Error GoTo Err_Form_Load
'Put the username in the text box
WorkerName = Forms![login]![txtuser]
'Close the login form
DoCmd.Close acForm, "Login"
'Get their username
'WorkerName = Forms![frm_main]![WorkerName]
'See if they are admin or have admin rights
If WorkerName = "admin" Or DLookup("admin", "tbl_worker", "WorkerName = '" &
WorkerName & "'") = "Yes" Then
admin.Visible = True
Managers.Visible = True
ManagersReports.Visible = True
ElseIf DLookup("Manager", "tbl_worker", "WorkerName = '" & WorkerName & "'")
= "Yes" Then
Managers.Visible = True
ManagersReports.Visible = True
Else
admin.Visible = False
Managers.Visible = False
ManagersReports.Visible = False
End If
DoCmd.Maximize
Exit_Form_Load:
Exit Sub
Err_Form_Load:
MsgBox Err.Description
DoCmd.OpenForm "Login"
DoCmd.Close acForm, "frm_main"
Resume Exit_Form_Load
End Sub