Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleConnect a DataReport to an ADO Recordset
KeywordsDataReport, ADO, Recordset
CategoriesDatabase
 
Open a Connection object to the database. Use the Connection object's Execute method to create a Recordset containing the desired records.

Then set the DataReport's DataSource property to the Recordset and display the DataReport.

 
Private Sub Command1_Click()
Dim db_file As String
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset

    ' Get the data.
    db_file = App.Path
    If Right$(db_file, 1) <> "\" Then db_file = db_file & _
        "\"
    db_file = db_file & "books.mdb"

    ' Open a connection.
    Set conn = New ADODB.Connection
    conn.ConnectionString = _
        "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & db_file & ";" & _
        "Persist Security Info=False"
    conn.Open

    ' Open the Recordset.
    Set rs = conn.Execute("SELECT * FROM Books", , _
        adCmdText)

    ' Connect the Recordset to the DataReport.
    Set rptBooks.DataSource = rs
    rptBooks.WindowState = vbMaximized
    rptBooks.Show vbModal

    rs.Close
    conn.Close
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated