The following example demonstrates how to set the
Connection object's
Mode property to
adShareDenyWrite, which allows the database to be opened from read-only media such as a CD-ROM drive. It also uses the
OpenSchema method to open the table's schema, to loop through, and to print all user-defined tables.
This example opens NWIND.MDB, which is located on your Office 2000 or Access 2000 CD.
NOTE: If your CD-ROM drive is not drive D, change the drive letter in the code to the correct one.
Sub OpenReadOnlyMDB()
Dim conn As ADODB.Connection
Dim rstSchema As ADODB.Recordset
Dim strCnn As String
Set conn = New ADODB.Connection
strCnn = "Provider=Microsoft.Jet.oledb.4.0;" & _
"Data Source=D:\PFILES\MSOFFICE\OFFICE\SAMPLES\NWIND.MDB"
conn.CursorLocation = adUseServer
conn.Mode = adShareDenyWrite
conn.Open strCnn
'Open the tables schema rowset
Set rstSchema = conn.OpenSchema(adSchemaTables)
'Loop through the results and print the names in the Immediate window
While Not rstSchema.EOF
If rstSchema.Fields("TABLE_TYPE") = "TABLE" Then _
Debug.Print rstSchema.Fields("TABLE_NAME")
rstSchema.MoveNext
Wend
rstSchema.Close
conn.Close
End Sub