Morning all
I know there is a method of producing a list of all the users currently using a database but these always are displayed as “Admin” because it uses the users and groups function within access to get the information.
Is there a way of making it display the users windows log on?
I've been playing on with the following code which populates the information in to a listbox. I can get the computer name to display correctly but not the username because as was expected the username again is always “admin”
I also have a function called ReturnNTName which grabs the current username (this works if I set a text box to display the ReturnNTName value) and have added the bits in bold to the code to see if this will display the username of the DB user in my list. But all this does is display my username against every user its doesn’t pull through the users username to display it separately to mine.
I hope this is possible as it would certainly make updating and collecting our stats much easier
Thanks in advance
I know there is a method of producing a list of all the users currently using a database but these always are displayed as “Admin” because it uses the users and groups function within access to get the information.
Is there a way of making it display the users windows log on?
I've been playing on with the following code which populates the information in to a listbox. I can get the computer name to display correctly but not the username because as was expected the username again is always “admin”
Code:
Private Sub GenerateUserList()
Const conUsers = "{947bb102-5d43-11d1-bdbf-00c04fb92675}"
Dim cnn As ADODB.Connection, fld As ADODB.Field, strUser As String
Dim rst As ADODB.Recordset, intUser As Integer, varValue As Variant
Set cnn = CurrentProject.Connection
Set rst = cnn.OpenSchema(Schema:=adSchemaProviderSpecific, SchemaID:=conUsers)
'Set List Box Heading
strUser = "Computer;UserName;Connected?;Suspect?[B];ID[/B]"
With rst 'fills Recordset (rst) with User List data
Do Until .EOF
intUser = intUser + 1
For Each fld In .Fields
varValue = fld.Value
'Some of the return values are Null-Terminated Strings, if
'so strip them off
If InStr(varValue, vbNullChar) > 0 Then
varValue = Left(varValue, InStr(varValue, vbNullChar) - 1)
End If
strUser = strUser & ";" & varValue
Next
[B]strUser = strUser & ";" & ReturnNTName[/B]
.MoveNext
Loop
End With
Me!txtTotalNumOfUsers = intUser 'Total # of Users
'Set up List Box Parameters
Me!lstUsers.ColumnCount = 5
Me!lstUsers.RowSourceType = "Value List"
Me!lstUsers.ColumnHeads = False
lstUsers.RowSource = strUser 'populate the List Box
'Routine cleanup chores
Set fld = Nothing
Set rst = Nothing
Set cnn = Nothing
End Sub
I also have a function called ReturnNTName which grabs the current username (this works if I set a text box to display the ReturnNTName value) and have added the bits in bold to the code to see if this will display the username of the DB user in my list. But all this does is display my username against every user its doesn’t pull through the users username to display it separately to mine.
I hope this is possible as it would certainly make updating and collecting our stats much easier
Thanks in advance