Option Compare Database
Option Explicit
Public Function ShowUserRosterMultipleUsers() As String
'Which computer has locked the database?
Dim cn As Object
Dim rs As Object
Dim strRetVal As String
Const c_adSchemaProviderSpecific As Integer = -1
Set cn = Application.CurrentProject.Connection
Set rs = CreateObject("ADODB.Recordset")
Set rs = cn.OpenSchema(c_adSchemaProviderSpecific, , "{947bb102-5d43-11d1-bdbf-00c04fb92675}")
'Represent a list of all users in current database.
strRetVal = rs.Fields(0).Name & "," & rs.Fields(1).Name & "," & rs.Fields(2).Name & "," & rs.Fields(3).Name
'Remove the NullChar behind every field. Use TrimNull.
Do While Not rs.EOF
strRetVal = strRetVal & vbCrLf & Left$(TrimNull(Nz(rs.Fields(0))) & Space(10), Len(rs.Fields(0).Name)) & _
"," & Left$(TrimNull(Nz(rs.Fields(1))) & Space(10), Len(rs.Fields(1).Name)) & _
"," & Left$(TrimNull(Nz(rs.Fields(2))) & Space(10), Len(rs.Fields(2).Name)) & _
"," & Left$(TrimNull(Nz(rs.Fields(3))) & Space(10), Len(rs.Fields(3).Name))
rs.MoveNext
Loop
ShowUserRosterMultipleUsers = strRetVal & vbCrLf
End Function
Public Function TrimNull(ByVal strItem As String) As String
'Remove the NullChar(\0) of the return string
Dim intPos As Integer
intPos = InStr(strItem, vbNullChar)
If intPos > 0 Then
TrimNull = VBA.Left$(strItem, intPos - 1)
Else
TrimNull = strItem
End If
End Function