Microsoft Knowledge Base Email Alertz

When you want to open a database read-only with the ActiveX Data Object (ADO) and the Jet 4.0 provider, the

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 275484 - Last Review: June 28, 2004 - Revision: 2.0

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

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 = "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
				

APPLIES TO
  • Microsoft Access 2000 Standard Edition
Keywords: 
kbhowto KB275484
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate