VB6 -> Crystal Reports: Subreport parameter prompt for link field
Posted on 2005-03-03
I've recently upgraded a VB6 application from Crystal 6 to Crystal 10. I'm now having problems running several reports which worked fine with Crystal 6.
The problem reports are those that have subreports (all the others work fine). Here's what happens.
I open a DAO dataset (rsData) and pass this to the main report
Set rsData = gdbHotel.OpenRecordset("SELECT keyItinerary, StartDate <etc ...> FROM tblCustItinerarys WHERE keyFBooking = 1", dbOpenDynaset)
.Database.Tables.Item(1).SetPrivateData 3, rsData
I then do the same for the subreport.
Set rsDataGuest = gdbHotel.OpenRecordset("SELECT keyFItinerary, Title, Forename, Surname FROM tblCustGuests WHERE keyFBooking = 1;, dbOpenDynaset)
For Each crSec In cryReport.Sections
For iCount = 1 To crSec.ReportObjects.Count
If crSec.ReportObjects.Item(iCount).Kind = crSubreportObject Then
Set crSub = crSec.ReportObjects.Item(iCount)
If crSub.SubreportName = "Guests" Then
Set crySubReport = crSub.OpenSubreport
crySubReport.Database.Tables.Item(1).SetPrivateData 3, rsDataGuest
(Code isn't particularly efficient, but it's always worked)
In this example the main report has a list of itineraries (the report is per itinerary), with the primary key: keyItinerary. This links to the Guests subreport on the field keyFItinerary. So the report has the link correctly established, and if you run the report in Crystal it works fine.
When you run it in VB, however, it prompts for the subreport parameter (Pm-dao.keyFItinerary) that the link is based on. If you give it a value, the report opens. The main body of the report is fine, but the sub-report will only have data for the value of keyItinerary that was manually input at the prompt. So, if the report has multiple pages, only one page will be correct. I'm passing the Guests subreport the correct data, it has all values of keyItinerary that could possibly be needed based on the data i'm passing the main report.
Hope that's clear ... it's early so i've done my best!
Any questions, let me know.