-
Hi team
I want to dynamically create an RS and then set the Crystal to look at it with "Database.SetDataSource myRS" (I'm Using the Crystal Reports Designer). But it doesn't work. It seems that Crystal is looking for a table rather than an RS. In DAO I could have created a table on the fly, but I can't see how to do that with ADO. Any bright ideas?
-
Here's an example of how I set a recordset to a report. I have a form named frmReport which contains a crystal report viewer control (crvCommon).
Code:
Dim rstCurrent As ADODB.Recordset
Dim strSql As String
Dim Report1 As rptAdjuster
strSql = "SELECT Adjuster.client_num, TRIM(Adjuster.adj_last)+', '+ TRIM(Adjuster.adj_first) as Name, Company.comp_name, Company.city "
strSql = strSql & "FROM openclose!company INNER JOIN openclose!adjuster "
strSql = strSql & "ON Company.comp_id = Adjuster.comp_id ORDER BY name"
Load frmReport
Set rstCurrent = New ADODB.Recordset
rstCurrent.Open strSql, fCnn1, adOpenForwardOnly, , adCmdText
Set Report1 = New rptAdjuster
Report1.Database.SetDataSource rstCurrent
frmReport.crvCommon.ReportSource = Report1
frmReport.crvCommon.ViewReport
frmReport.crvCommon.Visible = True
frmReport.Show
Hope this helps.
-
Thanks Derick
From freewilly re dynamically set CR record source
-
dcarlson,
I am having trouble with your code, it complains about the rptAdjuster data type in the line
Code:
Dim Report1 As rptAdjuster
I am using Crystal reports 8, would this have something to do with it, what version are you using.
-
rptAdjuster is the name my report. You need to create a report and replace rptAdjuster with the name of your report.
-
rptAdjuster?
Dcarlson,
I can't get your code to work either due to the rptAdjuster datatype. How did you reference rptAdjuster? I tried to add a reference to my report, but it didn't work. Please give a little more details.
-
You need to create report using the Crystal Report Designer Component within VB. You can do this by clicking on the Project menu and Add Crystal Reports 8. In my case, I named my report rptAdjuster and set an Object variable to that report. Replace rptAdjuster with the name of your report.
Code:
Dim Report1 as YourCrystalReport
If you want examples look under
C:\Program Files\Seagate Software\Crystal Reports\Samples\Code\Visual Basic
-
Derrick,
Thanks for the follow-up. I guess I'm having a problem because I don't have Crystal Report 8. I only have version 4.6 which shipped with Visual Studio.
However, I think I can figure out a solution to my problem.
Thanks again.