Link to home
Start Free TrialLog in
Avatar of feesu
feesu

asked on

Subreports Datasource

Experts,

I am using a crystal report designer imported into VB from an existing report, loading in crystal viewer.
My report uses sub reports. I am setting the reports datasource at rumtime, how can i set the datasource of the subreport at runtime?
Avatar of dkDeveloper
dkDeveloper

Hi feesu,

If you could post some information around which version of both Crystal and VB you are running we probably supply some more definite answers, but until then check out this knowledgeBase entry to see if that helps:

http://support.businessobjects.com/library/kbase/articles/c2010275.asp

Good Luck!
dK
link your subreport to your datasource.  you do this in the main report.  right-click on the subreport and set the link to your datasource there.
Avatar of feesu

ASKER

Hi dkDeveloper,
I am using crystal reports 9, VB 6..

Hi zephyr hex,
I wanted to link it at runtime by code.
sorry - no experience with the older versions.

dK
This isn't what you've asked, but I had tons of trouble linking tables together with multiple links.  The crystal example/documentation/help doesn't mention that the source and destination fields can be arrays.

Dim crTable1 As CRAXDRT.DatabaseTable
Dim crTable2 As CRAXDRT.DatabaseTable
Dim crDatabaseSourceField1(1) As CRAXDRT.DatabaseFieldDefinition
Dim crDatabaseDestField1(1) As CRAXDRT.DatabaseFieldDefinition

Set crTable1 = crReport.Database.Tables(iTable1)
Set crTable2 = crReport.Database.Tables(iTable2)

Set crDatabaseSourceField1(0) = crTable1.Fields(sSourceField1)
Set crDatabaseDestField1(0) = crTable2.Fields(sDestField1)

Set crDatabaseSourceField1(1) = crTable1.Fields(sSourceField2)
Set crDatabaseDestField1(1) = crTable2.Fields(sDestField2)

crReport.Database.Links.Add crTable1, crTable2, crDatabaseSourceField1, crDatabaseDestField1, crJTLeftOuter, crLTLookupParallel, False, True

I never tried to create a sub-report via code.
By the way, I don't think there are many differences between the old and new via code.  Or, at least I don't remember any.  I wrote with CR8.5 and moved to XI just before deploying.
ASKER CERTIFIED SOLUTION
Avatar of dylanyee
dylanyee

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of feesu

ASKER

Thanks you everyone for the help.

dylanyee,
The code you sent worked in vb6. But what do you put in the sub report name space? full path or a variable representing the report object?
feesu, just put the sub-report name will do. Every sub-report must have a name when you create it. To change your sub-report name, right click your subreport->Format subreport->subreport->subreport name.