Monday, July 18, 2011

How to Create a DataReport by Recordset?


Inculcated References file : Microsoft ActiveX Data Objects 2.0 Library

Using Module

Option Explicit

Public cn As New ADODB.Connection

Sub Main()

cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\NWIND.mdb;Persist Security Info=False"
cn.Open
Form1.Show
End Sub

Using Form

Option Explicit

Private Sub Command1_Click()

Dim rs As New ADODB.Recordset
rs.ActiveConnection = cn
rs.CursorType = adOpenStatic
rs.CursorLocation = adUseServer
rs.Open "SELECT * FROM Customers"

If rs.RecordCount > 0 Then
Set DataReport1.DataSource = rs
DataReport1.Show
End If

End Sub

Using DataReport

In Detail section
Use a text box and it's Properties DataField :CompanyName

No comments:

Post a Comment