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

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
 
G

Guest

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
 
G

Guest

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.
 
K

Ken Snell [MVP]

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>
 
G

Guest

Thanks for this. Unfortunately though I still get the same error:

Compile Error
Argument not optional
 
D

Douglas J. Steele

Show us all of the function, including the declaration of the function's
name.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)
 
A

aatcbbtccctc

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
 

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