Get Access Username & Group using VBA?

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

Guest

How do I return the Current User's username and Group membership info, using
VBA or MS Access objects?
 
Assuming you've applied Access security and you want their Access username
and what Access groups they're in, CurrentUser() will give you their
username, and the Security FAQ (at
http://support.microsoft.com/support/access/content/secfaq.asp ) includes
the following code:

List Groups User is a member of:

Function faq_ListGroupsOfUser (strUserName As String)
Dim ws As WorkSpace
Dim usr As User
Dim i As Integer

Set ws = DBEngine.Workspaces(0)
Set usr = ws.Users(strUserName)
For i = 0 To usr.Groups.count - 1
Debug.Print usr.Groups(i).Name
Next i
End Function
Determine if a User is in a given Group:

Function faq_IsUserInGroup (strGroup As String, strUser as String) As
Integer
' Returns True if user is in group, False otherwise
' This only works if you're a member of the Admins group.
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
strUserName = ws.groups(strGroup).users(strUser).Name
faq_IsUserInGroup = (Err = 0)
End Function
For Windows Id and security groups,
http://www.mvps.org/access/api/api0008.htm will get you their Id, but I
don't have code handy for getting their security groups.
 
Thanks. It looks like you knew exactly what I was trying to do. Yest Access
security is set up. I'll give it a try. Thanks very much!
 
Back
Top