Results 1 to 15 of 15
  1. #1
    Join Date
    Mar 2002
    Posts
    32

    Unanswered: Checking a User's group using VBA

    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?

    Thanks in advance

  2. #2
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    19
    I'm facing the same problem, is it so obvious that nobody posted anything? Please give me a hint!

  3. #3
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    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?

  4. #4
    Join Date
    Jun 2003
    Location
    UK
    Posts
    68
    Try CurrentUserGroup. Hope this is waht you are looking for.

    Paul

  5. #5
    Join Date
    Mar 2002
    Posts
    32
    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.


    Sub Form_Load()
    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

    Next i
    'Loop though groups until you get a match and set the curdept variable
    For i = LBound(GroupNames) To UBound(GroupNames)
    Select Case GroupNames(i)
    Case "Accounting"
    curdept = "Acct"
    GoTo DeptFound
    Case "MIS"
    curdept = "IS"
    GoTo DeptFound
    Case "Purchasing"
    curdept = "Purch"
    GoTo DeptFound
    Case "QA"
    curdept = "QA"
    GoTo DeptFound
    Case "R&D"
    curdept = "R&D"
    GoTo DeptFound
    Case "Sales"
    curdept = "Sales"
    GoTo DeptFound
    Case "Management"
    curdept = "Prod"
    GoTo DeptFound
    Case "Production"
    curdept = "Prod"
    GoTo DeptFound
    Case "CustServ"
    curdept = "Cust Serv"
    End Select
    Next i
    DeptFound:
    filter = "dept = " & "'" & curdept & "'"
    Form_ProjectMain.filter = filter
    Form_ProjectMain.FilterOn = True
    Last edited by BenCustalow; 03-01-04 at 10:28.

  6. #6
    Join Date
    Mar 2002
    Posts
    32
    Originally posted by Funkster
    Try CurrentUserGroup. Hope this is waht you are looking for.

    Paul
    Is this in one of ther newer access versions? There was no such thing in Access 2000.

  7. #7
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    19
    I'm trying to find out in which Windows-Group the current User is in. So what is this CurrentUserGroup? Google and MSDN don't find it.

  8. #8
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    19

    Smile

    Thanks Ben, that looks like the thing I'm after!

  9. #9
    Join Date
    Jun 2003
    Location
    UK
    Posts
    68
    Very sorry didn't look at what I was posting. Try

    Dim grp as Group

    Set grp = DBEngine(0).Groups(cboUserGroup)

    etc

    Paul

  10. #10
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    19
    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?

  11. #11
    Join Date
    Mar 2002
    Posts
    32
    Yes I am using access workgroup security with the system.mdw which is separate from windows. I haven't been able to authenticate access with windows users

    How do your users log into access?

    Are you in a Domain?

    If so Windows NT or Active Directory?

  12. #12
    Join Date
    Jun 2003
    Location
    UK
    Posts
    68
    Ah are you looking to link into Active Directory? Because I've been trying to move away from access security link to AD but have had no joy.

    Things are always more complicated thatn they first appear !!!

    Paul

  13. #13
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    19
    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?

  14. #14
    Join Date
    Mar 2002
    Posts
    32
    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.

  15. #15
    Join Date
    Mar 2004
    Posts
    3
    Originally posted by BenCustalow
    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.


    Sub Form_Load()
    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
    Sorry, but I think the real name of the variable curgroup is curdept (curgroup wan not used in the code), but the code for implement the solution is ok. Thank very much for this help!

Posting Permissions

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