Switchboard question!

J

JOM

I would like to enable and disable some of the buttons depending on access
level one has. in my Employee table, I have the following fields EName,
loginID, AccessLevel -- 1 grants all rights while 2 limits the rights ti what
can be accessed. How will I code it so that if your loginID isnot in the
database it provides the msgbox provided below and when one clicks ok, it
should exit.
So on my switchboard in the open event procedure, I have the following
Private Sub Form_Open(Cancel As Integer)
' Minimize the database window and initialize the form.

' Move to the switchboard page that is marked as the default.
Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "
Me.FilterOn = True

AL = DLookup("AccessLevel", "TblEmployee", "LoginID = '" &
Environ("username") & "' ")

If AL = 1 Then
With Me
.Option1.Enabled = True
.Option2.Enabled = True
.Option3.Enabled = True
.Option4.Enabled = True
End With

ElseIf AL = 2 Then

With Me
.Option1.Enabled = True
.Option2.Enabled = False
.Option3.Enabled = False
.Option4.Enabled = True
End With
Else
If IsNull(AL) Then
With Me
.Option1.Enabled = True
.Option2.Enabled = False
.Option3.Enabled = False
.Option4.Enabled = False
End With
End If
MsgBox "You do not have sufficient access to use this database/application" _
& Chr(13) & "See management", vbCritical, "Insufficient Database Access"

End If
End Sub
 
J

Jeff Conrad

in message:
I would like to enable and disable some of the buttons depending on access
level one has. in my Employee table, I have the following fields EName,
loginID, AccessLevel -- 1 grants all rights while 2 limits the rights ti what
can be accessed. How will I code it so that if your loginID isnot in the
database it provides the msgbox provided below and when one clicks ok, it
should exit.
So on my switchboard in the open event procedure, I have the following

Personally I would not use the Environ as that can be easily circumvented.
I would recommend using this code to retrieve the Network User ID:

http://www.mvps.org/access/api/api0008.htm

So using that API call just add in a few more lines of code like so:

If IsNull(DLookup("AccessLevel", "TblEmployee", "LoginID = '" & fOSUserName & "' ")) Then
MsgBox "You do not have sufficient permissions to use this database/application" _
& vbNewLine & vbNewLine & "Please see Management.", vbCritical + vbOKOnly, _
"Insufficient Database Access"
DoCmd.Quit
Exit Sub
Else
AL = DLookup("AccessLevel", "TblEmployee", "LoginID = '" & fOSUserName & "' ")
End If

If you still want to use Environ then just replace that part.
 
R

Ron2006

Watch out for a possible error situation.

I attempted that same type of thing but I was making the buttons
visible/not visible. I encountered the problem that when the FIRST
button was invisible (the user did not have access to that button), the
form would give me an error on opening because it was trying to set the
focus to that button. Enabling may not give you that type of problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top