Link to home
Start Free TrialLog in
Avatar of mvdwal
mvdwalFlag for Netherlands

asked on

Multiple active directory groups access to ms access form

I have the following code working in my ms access form (ms access 2007) with active directory users. Members in the purchase group have access.

But I need to know a code where multiple groups have access to this form. So if you are member of Sec-Purchase or Sec-Management.

Who knows how I can do this?

Here's my code:

  Private Sub Form_Open(Cancel As Integer)
    Dim strGroupWithAccess As String
   
   
    'Set the name of the group with access to this form.
    strGroupWithAccess = "Sec-Purchase"

   
    'Test if the user has access. If not, set Cancel to True and the form will not open.
    Cancel = Not IsMemberOfSecurityGroups(strGroupWithAccess)
   
    If Cancel = True Then
        MsgBox "You have no access to this form.", vbExclamation
    End If

End Sub


It's driving me crazy! I've tried a lot of options but my vb knowledge is limited...

Thanks a lot for helping me out!
Kind regards,
Michiel
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Just check for each group:

 Cancel = Not IsMemberOfSecurityGroups(strGroupWithAccess) OR Not IsMemberOfSecurityGroup(YourOtherGroup) OR Not IsMemberOfSecurityGroup(YourNextGroup)

If that doesn't work, you can always do this:

 Cancel = Not IsMemberOfSecurityGroups(strGroupWithAccess)

If Not Cancel Then
  Cancel = Not IsMemberOfSecurityGroups(YourNextGroup)
End If
ASKER CERTIFIED SOLUTION
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mvdwal

ASKER

Dear Peter,

Thanks a lot! It works!!!

I was spending hours on this form...
I did not check the other solution. But also many thanks for helping me out on this.

Do you have any tips to understand vb better? Maybe a good book? I wanna learn this!
Kind regards,
Michiel