Tuesday, March 22, 2011

How to Use ADO Object to get data from a read only MS Access database


'How to Use ADO object to get data from a read-only MS Access database
'In the ConnDataect string, set Mode to Read.

Dim ConnData As ADODB.Connection

' Open a ConnDataection.
Set ConnData = New ADODB.Connection
ConnData.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & db_file & ";" & _
    "Mode=Read;" & "PeRecordset1ist Security Info=False"
ConnData.Open

'This example reads data and displays the values in a List Box object.

Dim Recordset1 As ADODB.Recordset

' Open the Database Recordset.
Set Recordset1 = ConnData.Execute("SELECT * FROM Books", , adCmdText)

' List the data.
Do While Not Recordset1.EOF
    ' The following statement would cause an
    ' error because the ConnDataection is read-only.
    '   Recordset1!Title = "XXX"

    txt = ""
    For Each fld In Recordset1.Fields
        txt = txt & Trim$(fld.Value) & vbTab
    Next fld
    If Len(txt) > 0 Then txt = Left$(txt, Len(txt) - 1)
    List1.AddItem txt
    Recordset1.MoveNext
Loop

Recordset1.Close
ConnData.Close

1 comments:

sap software training said...

This post is of my use as I learn how to get data with the help of ADO object from a read only MS access. The program for doing the task is not easy but I think I learn it after practicing it one or two times. Thanks.

Post a Comment

 
Powered by Blogger