Graham may have something simpler, but this should get you going if you
are using Access 2000 and later, and want to know how many *distinct*
users there are (not merely now many connections):
1. Create a table in the front-end database, with these fields:
Computer_Name Text
Login_Name Text
Connected Yes/No
Suspect_State Number
EnteredOn Date/Time
JetUserRosterID AutoNumber (primary key)
Save the table with the name "tzJetUserRoster".
2. Paste the function below into a standard module.
Modify the strPath string so it points to your back end file.
Function UserCount() As Long
Dim cnLocal As ADODB.Connection 'Current project
connection.
Dim cnBackEnd As New ADODB.Connection 'Connection to back end
database.
Dim rsBEUserRoster As New ADODB.Recordset 'JET User Roster for back
end database.
Dim rsTarget As New ADODB.Recordset 'Temp table to record users
and de-dupe.
Dim strPath As String 'Full path to back end.
Dim strSql As String 'SQL string.
Dim lngKt As Long 'Loop controller.
Dim dtEnteredOn As Date 'Current date and time.
'Set this to the full path of your back end database.
strPath = "C:\Northwind2003.mdb"
'Open the JET User Roster for the back end.
cnBackEnd.Provider = "Microsoft.Jet.OLEDB.4.0"
cnBackEnd.Open "Data Source=" & strPath
Set rsBEUserRoster = cnBackEnd.OpenSchema(adSchemaProviderSpecific, , _
"{947bb102-5d43-11d1-bdbf-00c04fb92675}")
'Clear temp table, and copy the user roster in.
dtEnteredOn = Now()
Set cnLocal = CurrentProject.Connection
cnLocal.Execute "DELETE FROM tzJetUserRoster;"
rsTarget.Open "tzJetUserRoster", cnLocal, adOpenDynamic,
adLockOptimistic
Do While Not rsBEUserRoster.EOF
rsTarget.AddNew
For lngKt = 0 To 3
rsTarget(lngKt) = rsBEUserRoster(lngKt)
rsTarget!EnteredOn = dtEnteredOn
Next
rsTarget.Update
rsBEUserRoster.MoveNext
Loop
rsTarget.Close
rsBEUserRoster.Close
cnBackEnd.Close
'Get the count of the number of distinct users who are connected.
strSql = "SELECT DISTINCT Computer_Name FROM tzJetUserRoster WHERE
Connected = True;"
Set rsTarget = New ADODB.Recordset
rsTarget.Open strSql, cnLocal, adOpenKeyset
If Not (rsTarget.BOF And rsTarget.EOF) Then
rsTarget.MoveLast
UserCount = rsTarget.RecordCount
End If
rsTarget.Close
'Dereference objects
Set rsTarget = Nothing
Set rsBEUserRoster = Nothing
Set cnLocal = Nothing
Set cnBackEnd = Nothing
End Function
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
Josie said:
Hi Graham
OK - Plan B - how would you count the users?
TIA
Josie
Graham Mandeno said:
Hi Josie
You can count (or even list) the users who have your BE database open,
but AFAIK there is no way to narrow that down to a particular table.
Sorry!
--
Graham Mandeno [Access MVP]
Auckland, New Zealand
We have a Access 2002 database in a FE/BE config for 5 users.
Is there a means of counting how many users a using 1 particular table
at any one time. If it is possible advice on how to do the count would
be appreciated.
TIA
Josie