'will show all user's currently being connected to a database
'
'* based on information provided within the Microsoft KnowledgeBase *
Private Sub Transfer_UserRosterMultipleUsers(ByVal strPath_Filename_ToBackend As String)
Dim cn As adodb.Connection
Dim rs As adodb.Recordset
Dim strRowSource As String
Dim strUserToCheck As String
Set cn = New adodb.Connection
Set rs = New adodb.Recordset
lstConnections.RowSource = ""
DoCmd.Hourglass True
With cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Properties("Data Source") = mstrConnectedDB
If mconfSecuredDB Then
.Properties("User Id") = mcon_SEC_AdminsAcountName
.Properties("Password") = mcon_SEC_AdminsAcountPWD
.Properties("Jet OLEDB:System database") = getPath(mstrConnectedDB) & mcon_SEC_MDW_Name
End If
.Open
End With
'The user roster is exposed as a provider-specific schema rowset
'in the Jet 4 OLE DB provider. You have to use a GUID to
'reference the schema, as provider-specific schemas are not
'listed in ADO's type library for schema rowsets
Set rs = cn.OpenSchema(adSchemaProviderSpecific, , "{947bb102-5d43-11d1-bdbf-00c04fb92675}")
'Output the list of all users in the current database.
strRowSource = ""
'Debug.Print rs.Fields(0).Name, "", rs.Fields(1).Name, "", rs.Fields(2).Name, rs.Fields(3).Name
While Not rs.EOF
'Debug.Print rs.Fields(0), rs.Fields(1), rs.Fields(2), rs.Fields(3)
If mconfSecuredDB Then
strUserToCheck = mcon_SEC_AdminsAcountName
Else
strUserToCheck = CurrentUser
End If
If Trim(rs.Fields(1)) = strUserToCheck Then
'do not show the real name of the user that called this form
strRowSource = strRowSource & _
"""" & getCleanedString(rs.Fields(0)) & """;""" & "[Caller of form]" & """;""" & _
Choose(CBool(rs.Fields(2)) + 2, "Yes", "No") & """;""" & Nz(rs.Fields(3), "N/A") & """;"
Else
strRowSource = strRowSource & _
"""" & getCleanedString(rs.Fields(0)) & """;""" & getCleanedString(rs.Fields(1)) & """;""" & _
Choose(CBool(rs.Fields(2)) + 2, "Yes", "No") & """;""" & Nz(rs.Fields(3), "N/A") & """;"
End If
rs.MoveNext
Wend
'cut off trailing ';' and transfer to listbox
strRowSource = Left(strRowSource, Len(strRowSource) - 1)
lstConnections.RowSource = strRowSource
'clean up
rs.Close: Set rs = Nothing
cn.Close: Set cn = Nothing
DoCmd.Hourglass False
End Sub