Advertisement
ASP_Volume2 Databases/ Data Access/ DAO/ ADO #37810

Fill a DataReport with a Recordset

This code enable you fill a DataReport with the information contained in a Recordset. In this example, I have a connection with a database and I fill the Recordset with a SQL sentence.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
<pre>
This code enable you fill a DataReport with the 
information contained in a Recordset. In this 
example, I have a connection with a database and 
I fill the Recordset with a SQL sentence.
<b>First</b>, you have to add a DataReport to your project:
	Project > Add DataReport
<b>Design your report.</b>
The RptLabel tools are usually used as headers, 
but you can also use them in the report’s body 
and another places. The RptTextBox can be only 
on the body of the report and this tool receive 
the information from de recordset. In Properties 
you must give a different name to each 
RptTextBox.
The item’s parameter is the name of the 
RptTextBox which will receive the information.
<b>
DataReport1.Sections(“[SectionName”).Controls.Item(“[RptTextBoxName]”).DataField
</b>
I put the next code in the click event of a menu 
but you can put it in any other control 
(i.e.,CommandButton)
Dim Rs As New ADODB.Recordset
 Set Rs = Cn.Execute("Select ClientPK,NameClient,RepC,DomClient,TelClient,
CelClient,RFCClient,DateClient from Client order 
by(NomClient)")
 With DataReport1
 .DataMember = vbNullString
 Set .DataSource = Rs
 .Caption = "This is the Title of the DataReport window"
 With .Sections("Section1").Controls
 .Item("tNo").DataField = Rs.Fields(0).Name
 .Item("tName").DataField = Rs.Fields(1).Name
 .Item("tRep").DataField = Rs.Fields(2).Name
 .Item("tDom").DataField = Rs.Fields(3).Name
 .Item("tTel").DataField = Rs.Fields(4).Name
 .Item("tCel").DataField = Rs.Fields(5).Name
 .Item("tRFC").DataField = Rs.Fields(6).Name
 .Item("tDate").DataField = Rs.Fields(7).Name
 End With
 .Show
 End With
<br>
I hope it will be useful to you
</pre>
Original Comments (3)
Recovered from Wayback Machine