Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crystal reports unbound fields

Status
Not open for further replies.

mur3x

MIS
Sep 8, 2003
31
LK
Hi i use RDC (CR8.5) to display reports. I'm finding it very difficult on how to use unbound fields in a report.

i use the following code on Report form,

Code:
Dim cn As Connection 
Dim rs As Recordset
Dim Report As New CrystalReport1


Private Sub Form_Load() 'report form

Set cn = New Connection
Set rs = New Recordset

cn.Open "provider=microsoft.jet.oledb.4.0;data source=d:\my.mdb"

rs.Open "select id,date from receipts where date=" & strDate, cn

Report.DiscardSavedData
Report.Database.SetDataSource rs, 3, 1

CRViewer1.ReportSource = Report
CRViewer1.ViewReport

End Sub

so how can i use unbound fields for id & date. I wud really really appreciate any suggestions.

thnx!!!!
Mur.
 

When you insert an Unbound field in the report using the RDC, Crystal creates a formula field as a simple "placeholder". For example, if you place an Unbound string datafield on the report, right-click the field, and choose "Edit Formula" you'll see the code:

WhileReadingRecords;
Space(10)

The field name defaults to "UnBoundString1" (for the first one placed) which you will have to rename to match one of your column names in your select statement. This naming of the fields in the report to match the column names in the SQL statement will allow any recordset to be used as the datasource regardless of the table source. As long as the SQL statement aliases a column name to match the unbound field name (and data type) the report displays the data.

To set the unbound fields datasource to the newly assigned recordset you'll need to call the AutoSetUnboundFieldSource method:

Report.DiscardSavedData
Report.Database.SetDataSource rs, 3, 1
[green]Report.AutoSetUnboundFieldSource crBMTName[/green]



Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 
well thanks mark,,,but may i know what data tag & table number means, as in line

Code:
Report.Database.SetDataSource rs, 3, 1

I always get a run time error '9', "subscript out of range!"

Can u explain why this error occurs & also what does data tag & table number actually stands for???

thnx!!!
Mur
 

Sub SetDataSource (data, [dataTag], [tableNumber])

data = recordset
dataTag = the type of data (must be three (3) in 8.0/8.5)
tableNumber = index number of the table to be set (default=1)


The error comes from the report not having a datasource table (3rd param) defined when you try to modify the DataSource with the rs.

You can either create and save the report (design time) with a Datasource and modify it during runtime with the setDataSource

or

At runtime, add the datasource table using the AddOLEDBSource method:

Report.Database.AddOLEDBSource "connection", "tbl_name"
Report.Database.SetDataSource rs, 3, 1
Report.AutoSetUnboundFieldSource crBMTName





Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 
thnx mark!! thats great!!!
may i ask another question??

how to define a sql recordset not a table as in,

Code:
Report.Database.AddOLEDBSource "connection", "tbl_name"

to

Code:
Report.Database.AddOLEDBSource "connection", "select * from tbl_name"


thnx!
Mur.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top