LOCAL oCR AS CRAXDRT.Application LOCAL oRpt AS CRAXDRT.Report LOCAL oDB AS CRAXDRT.Database LOCAL ocDBT AS CRAXDRT.DatabaseTables LOCAL oDBT AS CRAXDRT.DatabaseTable LOCAL oConn AS ADODB.Connection LOCAL oRS AS ADODB.Recordset * Handle the ADO stuff oConn = CREATEOBJECT("ADODB.Connection") oConn.ConnectionString = "Provider=VFPOLEDB.1;Data Source=C:\eFox\Data\tastrade.dbc;Password=''" oConn.Open() oRS = CREATEOBJECT("ADODB.RecordSet") oRS.Open("Select * FROM Customer", oConn) oCR = CREATEOBJECT("CrystalRuntime.Application") oRpt = oCR.OpenReport("C:\EFox\ADO1.RPT") * Create the Database object oDB = oRpt.Database() * Get a references to the DatabaseTables collection ocDBT = oDB.Tables() * Get a reference to the DatabaseTable object for table 1 oDBT = ocDBT.Item(1) * Pass the Record Set to Crystal Reports oDBT.SetDataSource(oRS) IF oRPt.HasSavedData oRPT.DiscardSavedData() ENDIF oRpt.PrintOut()>I've created a CR 8.5 report, using the CR cross-tab expert. I created it using a temporary DBF with the same structure the RS will eventually have.
* Declare vars including: >LOCAL loConnection AS ADODB.CONNECTION, ; >loRS AS ADODB.RECORDSET, ; >loCommand AS ADODB.COMMAND, ; >loReport AS CrystalRuntime.REPORT, ; >loApp AS CrystalRuntime.Application > >*!* Initialize variables including: >loApp = CREATEOBJECT('CrystalRuntime.Application') >loReport = loApp.OpenReport(SalesAnalysisTotal) >loReport.DiscardSavedData > >*!* Create my SQL select based on user choices, detail isn't really important since RS gets created o.k. >lcCommand = "SELECT blah, blah, etc" > >*!* Create the connection >loConnection = CREATEOBJECT("ADODB.Connection") >loConnection.Mode = 16 && adModeShareDenyNone >lcConnection = ; > "Provider=VFPOLEDB.1;" + ; > "Data Source=" + CURDIR() + "DATA\;" + ; > "Mode=Share Deny None;" >loConnection.OPEN(lcConnection) > >*!* Create the recordset >loRS = CREATEOBJECT("ADODB.RecordSet") >loRS.LockType = 1 && Started with 3 >loRS.CursorLocation = 2 && Started with 3 >loRS.OPEN(lcCommand, loConnection) && Returns several thousand records as expected. > >ASSERT loRS.RecordCount > 0 MESSAGE "No records returned!" > >loReport.DiscardSavedData() && Altho the report is not saved with data, just for jollies. >loReport.DATABASE.SetDataSource(loRS,3,1) && Try and exchange the development source with the recordset. > >toCrViewer.ReportSource = loReport >toCrViewer.ViewReport()>When the report runs, CR reports that no records were selected and that there was error in the database dll. This is no doubt because the temporary table I used to create the report doesn't exist any longer. This tells me Crystal isn't using the RS I passed, but I have no idea why.