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
mvdwalAsked:
Who is Participating?
 
peter57rCommented:
You can build a more general procedure like this...(original code no longer required commented out)

Private Sub Form_Open(Cancel As Integer)
'store a list of groups with access to form in an array and test if user is in any of them

             ' Dim strGroupWithAccess As String
    Dim x as integer, OK as Boolean
    Dim OKArray(1)         ' set number of groups, base 0

' define array of groups with access
    OKArray(0)= "Sec-Purchase"
    OKArray(1)= "Sec-Management"  
   
            ' 'Set the name of the group with access to this form.
             ' strGroupWithAccess = "Sec-Purchase"
 OK = false
   for x = 0 to 1   ' loop through array; if any is allowed then OK = true
       OK =  IsMemberOfSecurityGroups(okarray(x))   or OK
   Next x
   
           'Test if the user has access. If not, set Cancel to True and the form will not open.
            'Cancel = Not IsMemberOfSecurityGroups(strGroupWithAccess)

  Cancel = not OK
   
    If Cancel = True Then
        MsgBox "You have no access to this form.", vbExclamation
    End If

End Sub
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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
0
 
mvdwalAuthor Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.