Trying to log users Logged in (1 Viewer)

Djblois

Registered User.
Local time
Today, 15:34
Joined
Jan 26, 2009
Messages
598
I found this code that finds a list of users that have a database open. I now want to open up a form with a table of all the people that have it open. I figure the best way is log it to a table and then use that table as a recordsource on a form. Then when I close the form, it deletes all records in the table. I am using this code to write it to the table:


Code:
Sub ShowUserRosterMultipleUsers()
    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim i, j As Long
    Dim sql As String

    On Error GoTo UnknownError
    Set cn = CurrentProject.Connection

    ' The user roster is exposed as a provider-specific schema rowset
    ' in the Jet 4.0 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.

    DoCmd.SetWarnings False
    
    rs.MoveFirst
    While Not rs.EOF
        sql = "INSERT INTO tblLoggedInUsers (Login_Name) VALUES('" & Trim(rs!Login_Name) & "');"
        'sql = "INSERT INTO tblLoggedInUsers (Login_Name, Computer_Name, Connected) VALUES('" & rs.Fields(1) & "', '" & rs.Fields(0) & "', '" & rs.Fields(2) & "');"
        MsgBox sql
        DoCmd.RunSQL sql
        rs.MoveNext
    Wend


The sql keeps on getting truncated. the single apostrophe after Trim(rs!Login_Name) and closing parenthesis and semi-colon are not showing up in the sql code.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 15:34
Joined
Oct 29, 2018
Messages
21,447
Hi. What is the value of rs!Login_Name?
 

Djblois

Registered User.
Local time
Today, 15:34
Joined
Jan 26, 2009
Messages
598

Users who are viewing this thread

Top Bottom