Admin vs. Data entry User

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to be able to hide a button from a currentuser() who DOES NOT
have Admin rights. what is the best way to do that?
 
If you are using User-Level Security, you can build an "IF" statement into
the form's open event that tests to see if the CurrentUser() is a certain
name (or names). Then set the control's 'visible' property accordingly.

There is a function out there that lets you test to see if a user is in a
particular group. This is the more correct way to handle it, but you would
have to build the function and call it in your code. CurrentUser() works
without any further code.

If you want to do the more correct method, do a search in the newsgroup for
previous posts contianing the string IsInGroup.

Good Luck.
 
Paulm said:
I would like to be able to hide a button from a currentuser() who
DOES NOT have Admin rights. what is the best way to do that?

I use the function below for this sort of thing:

'----- start of code -----
Function fncUserIsInGroup(GroupName As String) As Boolean

' Returns True if the current user is a member of the specified
' security group; False if not, or if the group doesn't exist, or
' if an error occurs reading the groups.

Dim ws As Workspace

Set ws = DBEngine.Workspaces(0)

On Error Resume Next
fncUserIsInGroup = _
(ws.Users(CurrentUser).Groups(GroupName).Name = GroupName)

Set ws = Nothing

End Function
'----- end of code -----

Then, in the Open event of a form, I can have code like this:

Me!cmdSomeButton.Visible = fncUserIsInGroup("Admins")
 
What you provided below makes sense. I understand where to put the Open even
info, however, where do I put the code for the Function Declaration?
 
Paulm said:
What you provided below makes sense. I understand where to put the
Open even info, however, where do I put the code for the Function
Declaration?

Paste it into a standard module -- one of those shown on the Modules tab
of the database window. If necessary, create a new standard module for
the purpose. When you save the module and are prompted for its name,
don't give it the same name as the function. You can leave it with the
name that Access proposes, like "Module1", or you can give it some name
that makes sense to you, so long as it isn't the same as any other
global name. I generally prefix module names with the characters "bas",
for "Basic code" (as in "basUtilities"), while others sometimes use the
prefix "mod" or "mdl", for "module". You aren't required to use a
prefix, but it helps ensure the module's name is unique.
 
Back
Top