Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get contents of laccdb file through VBA

I want to be able to view the contents of my access database's laccdb file through VBA so I can use it to alert users (through a button) who else is in the database.

I specifically don't want to use a 3rd Party tool. I have tried using:

Set ts = fso.OpenTextFile(strFile, ForReading)
strContents = ts.ReadAll

This works fine if only 1 user is in the database. But for multiple users it gets confused by the presumably non-ASCII characters and goes into this kind of thing after one entry:

complete gibberish

Does anyone have any suggestions? It's fine if I just open the file in Notepad++...


Code eventually used is as follows (I didn't need the title and have removed some code not being used):

Sub ShowUserRosterMultipleUsers()
Dim cn As New ADODB.Connection, rs As New ADODB.Recordset

cn.Provider = "Microsoft.ACE.OLEDB.12.0"
cn.Open "Data Source=" & CurrentDb.Name

Set rs = cn.OpenSchema(adSchemaProviderSpecific, , "{947bb102-5d43-11d1-bdbf-00c04fb92675}")
While Not rs.EOF
    Debug.Print rs.Fields(0)
    rs.MoveNext
Wend

End Sub
like image 315
Tim Edwards Avatar asked Sep 08 '16 13:09

Tim Edwards


People also ask

How do I read Laccdb files?

You need a suitable software like Access 365 from Microsoft Corporation to open a LACCDB file. Without proper software you will receive a Windows message "How do you want to open this file?" or "Windows cannot open this file" or a similar Mac/iPhone/Android alert.

What type of file is Laccdb?

laccdb" or ". ldb" file is created to store computer and security names and to place extended byte range locks. The lock file always has the same name as the opened database, and it's located in the same folder as the opened database.

Is there a way to see who has Access database open?

You can use utility software, such as the Computer Management utility or the Server Manager utility, to determine who has an Access database open in the exclusive mode and to determine what computer has an Access database open in the exclusive mode.


1 Answers

I found this which should help, it's not actually reading the ldb file, but it has the info that you need (Source: https://support.microsoft.com/en-us/kb/198755):

Sub ShowUserRosterMultipleUsers()
    Dim cn As New ADODB.Connection
    Dim cn2 As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim i, j As Long

    cn.Provider = "Microsoft.Jet.OLEDB.4.0"
    cn.Open "Data Source=c:\Northwind.mdb"

    cn2.Open "Provider=Microsoft.Jet.OLEDB.4.0;" _
    & "Data Source=c:\Northwind.mdb"

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

    Debug.Print rs.Fields(0).Name, "", rs.Fields(1).Name, _
    "", rs.Fields(2).Name, rs.Fields(3).Name

    While Not rs.EOF
        Debug.Print rs.Fields(0), rs.Fields(1), _
        rs.Fields(2), rs.Fields(3)
        rs.MoveNext
    Wend

End Sub
like image 66
Preston Avatar answered Oct 16 '22 08:10

Preston