Here's my VB6 code for passing data from .csv text files to a Crystal 8.5 report that also contains a subreport:
Private Sub Form_Load()
'*************************************************************
'PARSE THE COMMAND-LINE EXECUTABLE
'*************************************************************
'A directory folder is created by another program on the fly
'to hold the source data files created each time the report is requested.
'The folder name will vary each time the report is run.
'The name of the newly created folder is passed
'as a command line switch when this executable is launched.
'Parse the command line contents to extract the
'folder name and store it as a variable.
'Executable command line format is as follows:
'[VB6_program_name].exe/[source data folder name]
'Set a variable to hold # of chars in folder name
varFolderLen = Len(Command) - 1
'Set a variable to contain the folder name
varFolder = Right(Command, varFolderLen)
'Uncomment this line to verify report path
'MsgBox "SELECT * FROM " & App.Path & "\" & varFolder & "\" & "[main_report_datafile].csv", vbOKOnly
'*************************************************************
'SET THE REPORT OBJECT
'*************************************************************
Dim crxReport As CRAXDRT.Report
Set crxReport = crxApplication.OpenReport(App.Path & "\[main_report_name].rpt"
Dim crxSubreport As CRAXDRT.Report
Set crxSubreport = crxReport.OpenSubreport("[subreport_name].rpt"
crxReport.Database.SetDataSource Read_Text_File_Main, 3, 1
crxSubreport.Database.SetDataSource Read_Text_File_Sub, 3, 1
'************************************************************
'SET .PDF PARAMETERS AND OPTIONS
'************************************************************
'This report is set to automatically export to Adobe Acrobat
'(.pdf) format with no user prompts or interaction
'specify pdf format for output file
crxReport.ExportOptions.FormatType = crEFTPortableDocFormat
'Assign the export file name and location - exported file will
'be stored in the same folder where source data resides, and will
'be named with the same name as that folder + .pdf file extension
crxReport.ExportOptions.DiskFileName = varFolder & "\" & varFolder & ".pdf"
'Set option to export all pages of report to .pdf file to true
crxReport.ExportOptions.PDFExportAllPages = True
'Uncomment this line to display a progress bar as report is exported
'crxReport.DisplayProgressDialog = chkProgress.Value
'*************************************************************
'RUN THE EXPORT
'*************************************************************
'Export report without prompting user
'Note that setting the argument to False will fail if your CR Server doesn't
'have all the most up-to-date DLLs for report exporting.
'Setting the arg to True will avoid that problem, but will also cause
'a dialog to pop up during the export and prompt the user to specify
'filename and location.
crxReport.Export (False)
'Let the user know when the export is done
MsgBox "Report export to Adobe Acrobat (.pdf) format complete.", vbOKOnly + vbInformation, "Report Exported"
'*************************************************************
'CLOSE THE APPLICATION WINDOW, SHUT DOWN
'*************************************************************
Unload Me
End Sub
Private Function Read_Text_File_Main() As ADODB.Recordset
Dim rsMain As ADODB.Recordset
Set rsMain = New ADODB.Recordset
Dim connMain As ADODB.Connection
Set connMain = New ADODB.Connection
connMain.Open "DRIVER={Microsoft Text Driver (*.txt; *.csv)}" & _
";DBQ=" & App.Path & "\" & varFolder & "\" & _
";DefaultDir=" & App.Path & _
";Uid=Admin;Pwd=;"
rsMain.Open "SELECT * FROM " & App.Path & "\" & varFolder & "\[main_report_datafile].csv", connMain, adOpenStatic, adLockReadOnly, adCmdText
Set Read_Text_File_Main = rsMain
Set rsMain = Nothing
Set connMain = Nothing
End Function
Private Function Read_Text_File_Sub() As ADODB.Recordset
Dim rsSub As ADODB.Recordset
Set rsSub = New ADODB.Recordset
Dim connSub As ADODB.Connection
Set connSub = New ADODB.Connection
connSub.Open "DRIVER={Microsoft Text Driver (*.txt; *.csv)}" & _
";DBQ=" & App.Path & "\" & varFolder & "\" & _
";DefaultDir=" & App.Path & _
";Uid=Admin;Pwd=;"
rsSub.Open "SELECT * FROM " & App.Path & "\" & varFolder & "\[subreport_datafile].csv", connSub, adOpenStatic, adLockReadOnly, adCmdText
Set Read_Text_File_Sub = rsSub
Set rsSub = Nothing
Set connSub = Nothing
End Function
Private Sub Form_Unload(Cancel As Integer)
'Set the objects to 'Nothing' to remove them from memory.
'This ensures that each time you use these objects
'they are recreated and populated with new data.
Set crxReport = Nothing
Set crxSubreport = Nothing
End Sub