Identifying if CurrentUser() is in the 'Admins' Security Group

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

Guest

Hallo there

How do I identify in code whether the current user logged on (ie
CurrentUser()) belongs to the default 'admins' security group?

I need to do this so that I can 'grey out' some menu options when opening my
startup form when the CurrentUser does not belong to this security group.

Can any body help?

Are ideas/useful links are much appreciated.

Regards

Byz
 
Many thanks for this Ken. I've found the following code the article which
should allow me to run such a test:

Dim ws As Workspace
Dim grp As Group
Dim strUserName As String

Set ws = DBEngine.Workspaces(0)
Set grp = ws.Groups(strGroup)
On Error Resume Next

strGroup = "Admins"
strUser = CurrentUser()

strUserName = ws.Groups(strGroup).Users(strUser).Name
IsUserInGroup = (Err = 0)

However when I attempt to run the test from my startup form I get the
following error message:

'Argument not optional'.

In my start up form I have the following code for the test:

If IsUserInGroup=0 then
'Greyout certain menu options
Else
'Enable certain menu options
End If

Please can you tell me what I'm doing wrong?

Thanks

Byz
 
I think it's on this one:

strUserName = ws.Groups(strGroup).Users(strUser).Name

Although I'm not absolutely sure. The error I'm getting is a 'Compile Error'
which does not highlight or otherwise indicate the failing line after
striping out all error traps.

Thanks for your patience and help.
 
I believe that this line:
strUserName = ws.Groups(strGroup).Users(strUser).Name


should be this:
strUserName = ws.Users(strUser).Groups(strGroup).Name

--

Ken Snell
<MS ACCESS MVP>
 
Thanks for this. Unfortunately though I still get the same error:

Compile Error
Argument not optional
 
Show us all of the function, including the declaration of the function's
name.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)
 
Byzantine said:
Hallo there

How do I identify in code whether the current user logged on (ie
CurrentUser()) belongs to the default 'admins' security group?

(untested)

Function InGroup (pUser as string, pGroup as string) as boolean
dim s as string
on error resume next
s = dbengine(0).users(pUser).groups(pGroup).name
InGroup = (err.number = 0)
end function

Returns True if user pUser is in group pGroup, False if that user does
not exist or that group does not exist or that user is not in that
group.

For example:

if InGroup (CurrentUser(), "Admins") then
' current user is in Admins group.
else
' current user is not in Admins group.
endif

HTH,
TC
 
Back
Top