Results 1 to 9 of 9
  1. #1
    Join Date
    Oct 2003
    Posts
    18

    Unanswered: restricting groups

    Is there a way to restrict someone opening a form based on the group they belong to using the onOpen setting for instance ?

    If they don't belong to the required group then the form shuts down ?

  2. #2
    Join Date
    Mar 2003
    Location
    Romania
    Posts
    32

    Re: restricting groups

    You can use this:
    Function MatchUserGroup(strUser As String, strGroup As String) As Boolean
    Dim wrkDefault As Workspace
    Dim grpLoop As Group

    MatchUserGroup = False
    If strGroup <> "Users" Then
    Set wrkDefault = DBEngine.Workspaces(0)
    For Each grpLoop In wrkDefault.Users(strUser).Groups
    If grpLoop.Name = strGroup Then
    MatchUserGroup = True
    Exit For
    End If
    Next
    End If
    End Function

    You can use it like this:
    Private Sub Form_Load()
    If not MatchUserGroup(CurrentUser, "allowed_group") Then
    exit sub
    endif
    End Sub

    Florin
    Florin Profeanu
    floreanuprofin@yahoo.com

  3. #3
    Join Date
    Oct 2003
    Posts
    18
    That's a great start.

    Forgive my ignorance but where do i put the first block of code ?

    I take it the bottom part is put on the form load etc.

    My grasp of VB is limited to say the least.

  4. #4
    Join Date
    Oct 2003
    Posts
    18
    I've just put the first block of code in the general section on the form i am trying to protect.

    When i try and open the form with a non authorised user i get a compile error "User-defined type not defined" and the first line of code.........

    Function MatchUserGroup(strUser As String, strGroup As String) As Boolean

    is highlighted

    Any ideas`?

  5. #5
    Join Date
    Mar 2003
    Location
    Romania
    Posts
    32
    You can create a new module and paste the function there.
    In this way will be a public function and you can use it everywhere in your code.
    Florin Profeanu
    floreanuprofin@yahoo.com

  6. #6
    Join Date
    Oct 2003
    Posts
    18
    I tried that but it gives me another error message saying..

    "Expected Variable or Procedure, not Module"

    :-s not sure what i'm doing wrong...

  7. #7
    Join Date
    Mar 2003
    Location
    Romania
    Posts
    32
    See the attachement, works in Access 97.
    Attached Files Attached Files
    Florin Profeanu
    floreanuprofin@yahoo.com

  8. #8
    Join Date
    Oct 2003
    Posts
    18
    That works for me too after i converted it to 2000

    The only thing is now i can't get in to it at all.

    If strGroup <> "Users" Then

    Is that the line i should be modifying with the group i want to allow access.

    Sorry about this, i can't help but think i'm missing the point here.

    Thanks for all your help so far. Much appreciated.

  9. #9
    Join Date
    Oct 2003
    Posts
    18
    Got it working.

    It was me being stupid. Thanks for the help I owe you one.

    Thanks, Dave

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •