I am coding a form, and I want to check what group the person is a member of when they open the form. I get get there user name by using CurrentUser, but I don't know how to get there group name. I know that this information is stored in the system.mdw that I am using. Can someone help me?
Why do you want it? Setting the group permissions obviates the need for checking for it as part of the form initialization ... Are you trying to setup a scheme for security outside that built in Access?
I needed this to set a custom filter based on what department the person logging in was a member of. Here is the code I used. The important part is bold.
Dim UserName As String
Dim curgroup As String
Dim GroupNames(10) As String
Dim ws As Workspace
Dim usr As User
Dim i As Integer
Dim filter As String
UserName = CurrentUser
curdept = "Not Found"
Set ws = DBEngine.Workspaces(0)
Set usr = ws.Users(UserName)
'Put all groups user is in into an array For i = 0 To usr.Groups.Count - 1
GroupNames(i) = usr.Groups(i).Name
'Loop though groups until you get a match and set the curdept variable
For i = LBound(GroupNames) To UBound(GroupNames)
Select Case GroupNames(i)
curdept = "Acct"
curdept = "IS"
curdept = "Purch"
curdept = "QA"
curdept = "R&D"
curdept = "Sales"
curdept = "Prod"
curdept = "Prod"
curdept = "Cust Serv"
filter = "dept = " & "'" & curdept & "'"
Form_ProjectMain.filter = filter
Form_ProjectMain.FilterOn = True
Oh, I just noted that you're not using the windows groups, but the Access user groups, is that right? But how do you make them, you dont want to copy all the names of the windows users in your department to the access workgroups and give them manually the appropiate rights? I would like to read in which group they are in here in the network and that would tell me all I need. Must be somewhere in the registry -no?
Originally posted by BenCustalow
How do your users log into access?
Are you in a Domain?
If so Windows NT or Active Directory?
Yes, it Win2k and NT in this Network, suppose it is a Domain. But I know nothing of this Network stuff - just thought it would make things a lot easier if I could use the groups already existend and have them administrated only once. If you haven't done it yourself yet, maybe you have got some helpful links?
I actually don't think it can be done...at least not without alot of hard work.
Your best bet if you wish to go down this road is try and find documentation on "Authenticating Visual Basic to a Domain" or "Authenticating Visual Basic to Active Directory".
Some method's I've seen use the ADSI object. Not sure if this is available in VBA however.
I'd be very curious if you are able to make this work however so keep me posted.