Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: How to Open a Database from Read-Only Media with Microsoft Jet 4.0 and ADO


View products that this article applies to.

This article was previously published under Q275484
Moderate: Requires basic macro, coding, and interoperability skills.

This article applies only to a Microsoft Access database (.mdb).

↑ Back to the top


Summary

When you want to open a database read-only with the ActiveX Data Object (ADO) and the Jet 4.0 provider, the Connection object's Mode property must be set to adShareDenyWrite. This article demonstrates how to do this.

↑ Back to the top


More information

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
				

↑ Back to the top


Keywords: KB275484, kbhowto

↑ Back to the top

Article Info
Article ID : 275484
Revision : 2
Created on : 6/28/2004
Published on : 6/28/2004
Exists online : False
Views : 305