Results 1 to 9 of 9

Thread: access db logon list STILL looking for code help

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904

    access db logon list STILL looking for code help

    I just found this code (most of it) right here a couple of days ago. It is for the purpose of finding out who is logged on to an access db and co-incidentally a guy down the hall asked me to help him do just that so I thought I'd try to get this to work for me. I've lost track of the thread I sucked it off of and can't find it in search.

    my db connection opens just fine but I get error message 3251 "operator or provider is not capable of performing requested operation" at the line commented below.

    I commented out the line "If adxUsr.Name = cmbLogonId " 'cause it was giving a compiler error and I figured I"d get back to it when I got the rest working, but execution is halting at the commented line.

    I'm flying somewhat blind on this since I have not used these constructs before (catalog / group / user). On-line help isn't helping, but that's a common problem for me.

    My db references are

    MS ActiveX Data Objects 2.7 Library
    MS ADO Ext. 2.7 for DLL and Security

    VB Code:
    1. Option Explicit
    2. Public cn As ADODB.Connection
    3. '
    4. ' close db on cmd button pushed
    5. '
    6. Private Sub cmdClose_Click()
    7.     cn.Close
    8.     Set cn = Nothing
    9. End Sub
    10. '
    11. ' open db on cmd button pushed
    12. '
    13. Private Sub cmdOpen_Click()
    14.     Set cn = New ADODB.Connection
    15.     cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    16.                 "Data Source=" & "M:\SVC DEL COORD\open_items97.mdb"
    17.     cn.Open
    18. End Sub
    19. '
    20. ' find user on cmd button pushed
    21. '
    22. Private Sub Command1_Click()
    23.     Dim adxCat As ADOX.Catalog
    24.     Dim adxGrp As ADOX.Group
    25.     Dim adxUsr As ADOX.User
    26.     Dim cnt As Integer
    27.  
    28.     Set adxCat = New ADOX.Catalog
    29.     Set adxGrp = New ADOX.Group
    30.  
    31.     cnt = 1
    32.  
    33.     adxCat.ActiveConnection = cn
    34.     For Each adxGrp In adxCat.Groups ' <== ERROR MSG HERE <==
    35.         lstGroups.AddItem adxGrp.Name
    36.         cnt = cnt + 1
    37.     Next
    38.  
    39.     Set adxCat = New ADOX.Catalog
    40.     Set adxGrp = New ADOX.Group
    41.     Set adxUsr = New ADOX.User
    42.  
    43.     For cnt = 0 To lstGroups.ListCount - 1
    44.         lstGroups.Selected(cnt) = False
    45.     Next cnt
    46.  
    47.     Set adxCat = New ADOX.Catalog
    48.     Set adxUsr = New ADOX.User
    49.     Set adxGrp = New ADOX.Group
    50.  
    51.     adxCat.ActiveConnection = cn
    52.  
    53.     For Each adxUsr In adxCat.Users
    54. '        If adxUsr.Name = cmbLogonId Then
    55.             For Each adxGrp In adxUsr.Groups
    56.                 For cnt = 0 To lstGroups.ListCount - 1
    57.                     If adxGrp.Name = lstGroups.List(cnt) Then
    58.                         lstGroups.Selected(cnt) = True
    59.                     End If
    60.                 Next cnt
    61.             Next
    62. '        End If
    63.     Next
    64.     Set adxGrp = Nothing
    65.     Set adxUsr = Nothing
    66.     Set adxCat = Nothing
    67. End Sub

    any help will be appreciated
    Last edited by phinds; Jul 2nd, 2002 at 01:41 PM.

  2. #2
    Addicted Member Mandelbrot's Avatar
    Join Date
    Aug 2001
    Location
    Work, as usual!!
    Posts
    241
    PHinds,


    Try using the LDB file in the same folder as the database file. This stores the name of the Access database user. If you have a central datastore then you'll need to use the LDB stored in the same folder as this file.

    With XP, 2000 and NT you can obtain the current user name by asking for the einvironment variable:

    Debug.Print Environ$("USERNAME")

    But this will only return the user of the computer, not the database user.

    Hope this helps.


    Regards...

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    Mandelbrot, thank you. The LDB file does contain useful info.

    I'd still like to get the code sample working though, so if anyone can help with that, I'd appreciate it.

  4. #4
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    phinds, have not tried the code you posted, sorry.

    I have however a way of showing users currently logged into an access db.

    VB Code:
    1. Private Sub Command1_Click()
    2.     ShowUserRosterMultipleUsers
    3. End Sub
    4.  
    5. Sub ShowUserRosterMultipleUsers()
    6.     Dim cn As New ADODB.Connection
    7.     Dim cn2 As New ADODB.Connection
    8.     Dim rs As New ADODB.Recordset
    9.     Dim i, j As Long
    10.  
    11.     cn.Provider = "Microsoft.Jet.OLEDB.4.0"
    12.     cn.Open "Data Source=C:\TEST\From.mdb"
    13.  
    14.     cn2.Open "Provider=Microsoft.Jet.OLEDB.4.0;" _
    15.     & "Data Source=C:\TEST\From.mdb"
    16.  
    17.     ' The user roster is exposed as a provider-specific schema rowset
    18.     ' in the Jet 4 OLE DB provider.  You have to use a GUID to
    19.     ' reference the schema, as provider-specific schemas are not
    20.     ' listed in ADO's type library for schema rowsets
    21.  
    22.     Set rs = cn.OpenSchema(adSchemaProviderSpecific, _
    23.     , "{947bb102-5d43-11d1-bdbf-00c04fb92675}")
    24.  
    25.     'Output the list of all users in the current database.
    26.  
    27.     Debug.Print rs.Fields(0).Name, "", rs.Fields(1).Name, _
    28.     "", rs.Fields(2).Name, rs.Fields(3).Name
    29.  
    30.     While Not rs.EOF
    31.         Debug.Print rs.Fields(0), rs.Fields(1), _
    32.         rs.Fields(2), rs.Fields(3)
    33.         rs.MoveNext
    34.     Wend
    35.  
    36. End Sub

    this works. Taken from the MSDN
    -= a peet post =-

  5. #5
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    found the article : http://support.microsoft.com/directo...EN-US;Q198755&

    tells you more about the sample and how it works.
    -= a peet post =-

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    Peet, thank you. This works although it tells me I'm logged on whether I am or not but this seems to be because I'm the db admin and it lists the admin whether anyone is logged on or not.

    the "{947bb102-5d43-11d1-bdbf-00c04fb92675}" is certainly intuitively obvious; why didn't I think of that? I just love the straightforward way MS does these things. I'll check out the whole thing --- thanks for providing the reference and thanks again for the solution.

    SO ... you've solved my immediate problem, but I'd STILL like to get my code snippet working because
    (1) it apparently has the ability to report on groups as well as users, which would be nice to know
    (2) I'm a persistant bastard
    (3) I HATE mysteries such as why the &^$#& doesn't it work?

  7. #7
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Originally posted by phinds
    the "{947bb102-5d43-11d1-bdbf-00c04fb92675}" is certainly intuitively obvious; why didn't I think of that? I just love the straightforward way MS does these things. I'll check out the whole thing --- thanks for providing the reference and thanks again for the solution.


    I do agree

    I'll give the code above a go later on, and let you know if I'm able to find out anything useful
    -= a peet post =-

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    bump

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    bump one more time

Posting Permissions

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



Click Here to Expand Forum to Full Width