by Brian Gillham (7 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: Visual Basic 5.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (4 Votes)
These Functions will allow you to determine WHO is logged on to the Acces Database as well as HOW MANY users are logged-in. As always the code is FREE, if you want support can consult me in my professional capacity. ENJOY
Public Function EmptyRS(ByVal oRS) As Boolean
On Error Resume Next
'Checks for an EMPTY RecordSet
EmptyRS = True
If Not oRS Is Nothing Then
EmptyRS = ((oRS.BOF = True) And (oRS.EOF = True))
End If
End Function
Public Function GetDBUsers() As ADODB.Recordset
' NOTES: Fields as follows
' 0 - COMPUTER_NAME: Workstation
' 1 - LOGIN_NAME: Name used to Login to DB
' 2 - CONNECTED: True if Lock in LDB File
' 3 - SUSPECTED_STATE: True if user has left database in a suspect state(else Null)
On Error GoTo LocalError
Const JET_SCHEMA_USERROSTER = "{947bb102-5d43-11d1-bdbf-00c04fb92675}"
' Return a Disconnected RecordSet
If cnADO.State = adStateOpen Then
Set GetDBUsers = cnADO.OpenSchema(adSchemaProviderSpecific, , JET_SCHEMA_USERROSTER)
Set GetDBUsers.ActiveConnection = Nothing
End If
LocalError:
End Function
Public Function GetDBUserCount() As Long
On Error GoTo LocalError
Dim lRS As ADODB.Recordset
Set lRS = GetDBUsers
If Not EmptyRS(lRS) Then
GetDBUserCount = lRS.RecordCount
lRS.Close
End If
LocalError:
Set lRS = Nothing
End Function