what permissions does the logged in user have

  • Thread starter Thread starter tw
  • Start date Start date
T

tw

Is there a way to tell what permissions a user has to either enable or
disable menu items based on the permissions they have rather than letting
the error handler tell them they don't have permission to do an option that
was enabled on the menu or elsewhere?
 
The usual way to handle this is to check if the currently logged
on user is a member of a specific Group. So, for example, if
Bob logs in and wants to access a menu option, you first check
to see if Bob is a member of a Group that you wish to access
that option. If he is not a member that you want to access that
function, then you pop up a nice message box.

There are many functions out there to test for Group membership.
This one is straight out of the Security FAQ (with a few changes):

Public Function faq_IsUserInGroup(strGroup As String, _
strUser As String) As Boolean
' Returns True if user is in group, False otherwise
Dim ws As DAO.Workspace
Dim grp As DAO.Group
Dim strUserName As String

Set ws = DBEngine.Workspaces(0)
Set grp = ws.Groups(strGroup)
On Error Resume Next
strUserName = ws.Groups(strGroup).Users(strUser).Name
faq_IsUserInGroup = (Err = 0)
End Function

Copy and paste that code into a new standard module.
Make sure you set a reference to the DAO object library
if you have not already.
Make sure you name the module something other than
the function name. Like basSecurityFunctions for example.

To call the function you do this:

If faq_IsUserInGroup("SomeGroupNameHere",CurrentUser())=True Then
' They are a member so do something
Else
' They are not a member of that group so do something else
End If

--
Jeff Conrad
Access Junkie
Bend, Oregon

"tw" wrote in message
 
thanks
Jeff Conrad said:
The usual way to handle this is to check if the currently logged
on user is a member of a specific Group. So, for example, if
Bob logs in and wants to access a menu option, you first check
to see if Bob is a member of a Group that you wish to access
that option. If he is not a member that you want to access that
function, then you pop up a nice message box.

There are many functions out there to test for Group membership.
This one is straight out of the Security FAQ (with a few changes):

Public Function faq_IsUserInGroup(strGroup As String, _
strUser As String) As Boolean
' Returns True if user is in group, False otherwise
Dim ws As DAO.Workspace
Dim grp As DAO.Group
Dim strUserName As String

Set ws = DBEngine.Workspaces(0)
Set grp = ws.Groups(strGroup)
On Error Resume Next
strUserName = ws.Groups(strGroup).Users(strUser).Name
faq_IsUserInGroup = (Err = 0)
End Function

Copy and paste that code into a new standard module.
Make sure you set a reference to the DAO object library
if you have not already.
Make sure you name the module something other than
the function name. Like basSecurityFunctions for example.

To call the function you do this:

If faq_IsUserInGroup("SomeGroupNameHere",CurrentUser())=True Then
' They are a member so do something
Else
' They are not a member of that group so do something else
End If

--
Jeff Conrad
Access Junkie
Bend, Oregon

"tw" wrote in message
 
Jeff said:
The usual way to handle this is to check if the currently logged
on user is a member of a specific Group. So, for example, if
Bob logs in and wants to access a menu option, you first check
to see if Bob is a member of a Group that you wish to access
that option. If he is not a member that you want to access that
function, then you pop up a nice message box.

Just a thought. I think it's better to hide the item they don't have
permission for. Getting a message (nice or not) is just grating to a lot of
users.
 
Just a thought. I think it's better to hide the item they don't have
permission for. Getting a message (nice or not) is just grating to a lot of
users.

Come to think of it, I do the same thing!
Geez, I'm getting old.
Thanks Joan for the additional suggestion.
 
Thanks all,
My original question was to disable the item... hiding is fine too. I just
let your suggestion of the message box pass right by. I wanted to get away
from the message box.
 
in message
It happens to the best of us, Jeff.. ;-)

<g>
Yep.

Well, I guess I can think positive and remember I'm not as old as Fred.
<g, d, r>

......wait a minute.....I guess I do not have to run *that* fast.

he...he...he...
 
Back
Top