Try to extract user name or group info from within vb macro window

A

Alan Cantor

Hi, your help is much appreciated.

I'm writing an Access 2002 db that has it's own mdw user/group definitions.
After a user logs on and is using one of the forms, they have the option to
check a box.

Basically, I would like to give the ability to check this special box to
admin users and NOT regular New Data Users. How do I do this?

My thoughts were to use the vb (alt-f11) macro code builder to check the
(Access.Users.CurrentlyLoggedOnUser.Group - pipe dream eh?) access
automation object somehow to extract the group or the username or the
userlevel (anything) from within the CHECKBOX_ONCLICK event. You know..
something like...

sub checkboxname_onclick()
'this ? ...
if user.level < 1 then
msgbox("you're hosed")
end if
'or this ? ...
if user.group <> "adminGroup" then
msgbox("too bad buddy")
end if
end sub

Basically, my question is .... IS this a way to access the
currently-logged-on-user information programmatically from the access
automation objects available in the F2 object browser?

Thanks for your help,
Alan Cantor
 
A

Albert D. Kallal

You can use:


if IsInGroup(CurrentUser(),"Admins") = True then
bla bla bal..

The function I use is reproduced below. Note that CurrentUser() is a built
in access function that always returns the current logged in user name (to
the workgroup file).


Public Function IsInGroup(UsrName As String, GrpName As String) As Boolean
'Determines whether UsrName is a member of GrpName

Dim grp As Group
Dim IIG As Boolean
Dim usr As user

IIG = False

For Each usr In DBEngine.Workspaces(0).Users
If usr.Name = UsrName Then GoTo FoundUser
Next

GoTo IIG_Exit

FoundUser:
For Each grp In usr.Groups
If grp.Name = GrpName Then IIG = True
Next

IIG_Exit:
IsInGroup = IIG


End Function
 

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