Results 1 to 7 of 7
  1. #1
    Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Is this user in this group?

    I would like to write a function that tests whether a user is a member of a particular security group, based on their user name. Does anyone know if I can do this?

  2. #2
    Lounger
    Join Date
    Feb 2001
    Location
    TX, USA
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Is this user in this group?

    If you have the Acees Developers Handbook by Gilbert, Getz & Litwin, you would already have that. If you don't have the book, I would HIGHLY recommend purchasing it.

  3. #3
    Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Is this user in this group?

    I don't have it, but I'll get it as soon as I can. In the meantime, is there a simple answer to my question?

    Thanks,

  4. #4
    Lounger
    Join Date
    Feb 2001
    Location
    TX, USA
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Is this user in this group?

    All I would end up doing is giving away their code which is pretty unethical. their code is free to use as long as you purchase their book or find it published in one of their many articles in periodicals or on the web. Sorry, but maybe someone else wrote a custom module they will post for you

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Is this user in this group?

    Here's a routine from NeatCd97.mdb, which is (or was) downloadable from the Microsoft site.

    <pre>Function UserInGroup(UName As String, _
    GName As String) As Integer
    '
    ' Checks whether the user name specified
    ' belongs to the group name specified.
    ' This is specific to the current system.mdw only.
    '
    Dim w As Workspace, U As user, i As Integer, _
    Found As Integer
    UserInGroup = False
    Set w = DBEngine.CreateWorkspace("", "Admin", "")
    ' 2nd arg=Admins level user name, 3rd=Password
    '
    ' Checks if user name is valid for this system.mdw
    '
    Found = False
    For i = 0 To w.Users.Count - 1
    If w.Users(i).Name = UName Then
    Found = True
    Set U = w.Users(i)
    Exit For
    End If
    Next i
    If Not Found Then
    MsgBox "User '" & UName _
    & "' is not a valid user name."
    Exit Function
    End If
    '
    ' Check if user is in the group
    '
    For i = 0 To U.Groups.Count - 1
    If U.Groups(i).Name = GName Then
    UserInGroup = True
    Exit Function
    End If
    Next i
    End Function</pre>

    Charlotte

  6. #6
    Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Is this user in this group?

    I got this function from someone else, and it works fine for me (I use my own MDW file), but a user with restricted access gets the error "No read permission on table 'MSysGroups'". I can't figure out what permissions I can grant to avoid this error. I've commented the code where the error occurs.

    BTW I use Access 97.



    Function libCheckGroup(strGroupCheck As String) As Boolean

    Dim wrkDefault As Workspace
    Dim usrNew As User
    Dim usrLoop As User
    Dim grpNew As Group
    Dim grpLoop As Group
    Dim grpMember As Group

    Set wrkDefault = DBEngine.Workspaces(0)
    With wrkDefault
    ' Enumerate all Group objects in the default
    ' workspace's Groups collection.
    For Each grpLoop In .Groups
    If grpLoop.Name = strGroupCheck Then
    '***********user gets error on next line*************
    If grpLoop.Users.Count <> 0 Then
    For Each usrLoop In grpLoop.Users
    If UCase(usrLoop.Name) = UCase(CurrentUser) Then
    libCheckGroup = True
    Exit Function
    End If
    Next usrLoop
    End If
    End If
    Next grpLoop
    End With
    End Function

  7. #7
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Is this user in this group?

    Only a user with the necessary permissions can look at the system tables, which usually means an administrator. That's what this line
    <hr> Set w = DBEngine.CreateWorkspace("", "Admin", "") <hr>
    in the code I posted is doing. It's creating a workspace using the Admin user name so it will have access to the system tables even though the current use may not have that level of permissions.
    Charlotte

Posting Permissions

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