Using JetUserRoster from Access database

I'm trying to get a list of users who are currently logged into a database from that current database.  I'm developing an Administrator tools menu that displays who is currently logged in to the database.  I've developed a similar application with VB using the code below:

Public Sub GetCurrentUsers(strConnection As String)

On Error GoTo err_trap:

    Dim cn As New ADODB.Connection
    Dim rstUserList As New ADODB.Recordset
    Dim LineItem As ListItem
    Dim i As Integer
    i = 0
    cn.Provider = "Microsoft.Jet.OLEDB.4.0;"
    'cn.Properties("Jet OLEDB:System database") = strMDWPath
    cn.Open strConnection
    Set rstUserList = cn.OpenSchema(adSchemaProviderSpecific, _
    , "{947bb102-5d43-11d1-bdbf-00c04fb92675}")
    With Me.ctlListView.ListItems
        Do Until rstUserList.EOF
            Set LineItem = .Add(, , "")
            LineItem.SubItems(1) = IIf(Len(rstUserList.Fields(0)) > 0, rstUserList.Fields(0), "")
            LineItem.SubItems(2) = IIf(Len(rstUserList.Fields(1)) > 0, rstUserList.Fields(1), "")
            LineItem.SubItems(4) = IIf(Len(rstUserList.Fields(2)) > 0, rstUserList.Fields(2), "")
            LineItem.SubItems(5) = IIf(Len(rstUserList.Fields(3)) > 0, rstUserList.Fields(3), "False")
        Set rstUserList = Nothing
        Set cn = Nothing
    End With
    Call SetupCurrentUserList

    DoCmd.Hourglass False
    Exit Sub
    MsgBox "Error Number: " & Err.Number & vbCr & "Description: " & Err.Description, _
            vbCritical, "ERROR"
    Resume Exit_Sub
End Sub

Public Sub SetupCurrentUserList()
Dim LineItem As ListItem

'Set Status
If Me.ctlListView.ListItems.Count = 1 Then
    Me.txtStatus = "No users connected other than this program."
    Me.txtStatus = Me.ctlListView.ListItems.Count & _
        " users connected (including the connection maintainted by this program)."
End If

'Set Icons
With Me.ctlListView
    For Each LineItem In .ListItems
        If LineItem.SubItems(5) = "True" Then
            LineItem.SmallIcon = "suspect"
            If CurrentMachineName = LineItem.SubItems(1) Then
                LineItem.SmallIcon = "comp"
                If LineItem.SubItems(4) = "True" Then
                    LineItem.SmallIcon = "network"
                    LineItem.SmallIcon = "network_closed"
                End If
            End If
        End If
End With

End Sub

When I want to populate the user list I call GetCurrentUsers(  It gives me the following error:

Error Number: -2147467259
Error Description: The database has been placed in a state by user 'Admin' on machine 'HPHome' that prevents it from being opened or locked.

I know the problem is that I am trying to use JetUserRoster to open the datatabase that I currently in.  

Any suggestions on how I can modify the code above to get the user list using JetUserRoster of the database that I am currently in??

Any help would be greatly appreciated...
Who is Participating?
moduloConnect With a Mentor Commented:
PAQed with points refunded (70)

Community Support Moderator
jg0069_2002Author Commented:
I think I've figured it out, so I guess I need to withdraw the question.  What I did was the following:

In the GetCurrentUsers subroutine, I replaced:

    cn.Provider = "Microsoft.Jet.OLEDB.4.0;"
    'cn.Properties("Jet OLEDB:System database") = strMDWPath
    cn.Open strConnection

with Set cn = CurrentProject.Connection

and everything worked as planned...
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Yes, post a question in Communit Support to do delete the question (with a pointer back to this question)
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.