Click to See Complete Forum and Search --> : VB6 Data Report Problem--Need Help Fast


John Watson
May 25th, 1999, 11:49 AM
I posted the question about Crystal Reports below. Sorry for posting twice, but I just read elsewhere in this list that it is possible to use an existing ADO recordset as the data source for a VB6 DataReport, and then bind the report controls to the recordset fields. I tried

Set DataReport1.DataSource = [my recordset name]

but I keep getting the "Invalid Data Source"
message. Can anyone give me the code to do this with the Data Report?

Thanks,

John

Jaime Herrero
May 25th, 1999, 11:59 AM
Hi John.
I had the same trouble. Try to do the following steps and i think itīll work

1. Catch the error
On Error Resume NExt
2.And then bind the fields of your datareport with
the fields of your Recordset.
3. At last, refresh your report
Me.Refresh

Put the previous code in the event initialize of the DataReport.

It works for me. Iīm working with ADODB Recordsets
filled calling a ADODB.Command.

If you donīt success, report me the trouble and iīll try to help you, but be sure it works.

Hope it helps!
Bye
JaIme

rbandaru
May 25th, 1999, 02:07 PM
Here is the sample code for running reports with ADO recordsets. If you have any more question feel free to mail me. I have more stuff on how to develop grouping reports using ADO's and recordsets. My email Id is bandarurr@hotmail.com

Good luck

The following code goes into the module:

option Explicit
public MyConn as ADODB.Connection
public myRec as ADODB.Recordset
public myRec1 as ADODB.Recordset

Sub main()
set myRec = new ADODB.Recordset
set myRec1 = new ADODB.Recordset
set MyConn = new ADODB.Connection

With MyConn
.Provider = "Microsoft.jet.oledb.3.51"
.Open "C:\Program Files\Microsoft Visual Studio\VB98\Biblio.mdb"
End With


myRec1.Open "SELECT * From Publishers ", MyConn, adOpenStatic, adLockOptimistic

Form1.Show

End Sub




The following code goes into the command1 click event


DataReport1.Visible = true




The following code goes into the report initialisation section:


private Sub DataReport_Initialize()

With DataReport1
set .DataSource = myRec1
.Sections.Item(3).Controls.Item(1).DataField = myRec1.Fields(0).Name
.Sections.Item(3).Controls.Item(2).DataField = myRec1.Fields(1).Name
End With
End Sub