Microsoft KB Archive/275484

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

Article ID: 275484

Article Last Modified on 6/28/2004

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



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).



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.



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 = &quot;Provider=Microsoft.Jet.oledb.4.0;&quot; & _ &quot;Data Source=D:\PFILES\MSOFFICE\OFFICE\SAMPLES\NWIND.MDB&quot; 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(&quot;TABLE_TYPE&quot;) = &quot;TABLE&quot; Then _ Debug.Print rstSchema.Fields(&quot;TABLE_NAME&quot;) rstSchema.MoveNext Wend rstSchema.Close conn.Close End Sub

Additional query words: read only readonly

Keywords: kbhowto KB275484

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.