Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking Group Membership Without Being Admin

Status
Not open for further replies.

tjherman

Programmer
Jun 19, 2006
68
US
I'm wanting to check group membership for a user and choose to display or not display various buttons on a form. I have found some code that works fine as long as you are an Admin; however, if you're not an Admin and open the program in Access 2000 or 2003, it will open fine the first time but then give an error the 2nd time and subsequent times.

Basically, does anyone know of any code that can be used to check if a user is a member of a particular group -- regardless of whether the user is an Admin or standard User?

(The code below is what I use and it works consistently but only if the logged in user is an Admin...

Dim ws As Workspace
Dim grp As Group
Dim strGroup
Dim strUser
strGroup = "Admins"
strGroup2 = "Users"
strUser = CurrentUser

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

If IsAdmin = False Then
Me!Command41.Visible = False
Me!Label42.Visible = False
Else
Me!Command41.Visible = True
Me!Label42.Visible = True
End If
 
This is goofy, but a possible work around.

You can set security on macros.

Macros can run code.

You can make macros that run functions that set global variables for each group or set a single global variable to a group name.

From code use ON Error Resume next and call all possible macros. Run this code on the on open event of your databases startup form or call it from the autoxec macro.

Use the global variable(s) to control what is displayed.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top