Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


How do I check if a database is open

How do I check if a database is open

How do I check if a database is open

I need a way to check when the database is opened to see if it is already open by another user. If the user is the 'first' in then I want to run some update instructions.

I know I can check for the existence of the dbName.ldb file in the same directory but as soon as I open the database the file exists. So I have not been able to make this work from within the database I open.


Every day I get up and look through the Forbes list of the richest people in America.  If I'm not there, I go to work.


RE: How do I check if a database is open


Public Sub ADOUserList(oConn As ADODB.Connection)
    Dim rs As ADODB.Recordset
    Set rs = oConn.OpenSchema(adSchemaProviderSpecific, , "{947bb102-5d43-11d1-bdbf-00c04fb92675}")
    Debug.Print rs.GetString
End Sub

-You must pass an open connection object to this proceedure:
Call ADOUserList(MyConnectionObjectVariable)
Call ADOUserList(Form1.ADODC1.Recordset.ActiveConnection)

-The first value is the machine
-The second is the user name
-The third is a boolean (0=False; -1=True) and identifies if the user is still logged in or not.

-All values reset when all connections are closed.

-Multiple entires can exist for the same user and machine, even if only one Application is using the db, because an entry shows for each connection to the mdb.

RE: How do I check if a database is open

Yes, and this is assumming you are using an Access/Jet database.

You can use the recordset object to get specific info back:


Public Sub ADOUserList(oConn As adodb.Connection)
    If Not (oConn Is Nothing) Then
        Dim rs As adodb.Recordset
        Set rs = oConn.OpenSchema(adSchemaProviderSpecific, , "{947bb102-5d43-11d1-bdbf-00c04fb92675}")
        Do Until rs.EOF
            If rs.Fields("CONNECTED").Value = True Then
                Debug.Print "User '" & Trim$(rs.Fields("LOGIN_NAME").Value) & "' " & _
                        "on machine '" & Trim$(rs.Fields("COMPUTER_NAME").Value) & "' " & _
                        "is currently logged on to: " & vbCr & _
                        rs.ActiveConnection.ConnectionString & vbCr & vbCr
            End If
    End If
End Sub

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close