I am using Crystal reports XI and I am using this code to print reports after a transaction. This code works fine but the Problem comes when I attempt a second transaction, I get the error "Method ReportSource of object ICrystalReportViewer11 failed". However If i do a transaction and print the report and close the form after that and then come back into the form to do the second transaction the code works fine. I am convinced that the solution is that I need to "dispose" the reportviewer and "initialise" it when I need to use it but I just need some guidance on how to do this any help.
Code:
Dim app As New CRAXDRT.Application
Dim rpt As New CRAXDRT.Report
Dim tbl As CRAXDRT.DatabaseTable
Set rpt = app.OpenReport("C:\SOS3000\NewReports\DNOPS01.rpt")
rpt.DiscardSavedData
For Each tbl In rpt.Database.Tables
tbl.ConnectionProperties.DeleteAll
tbl.ConnectionProperties.Add "Provider", "MSDASQL"
tbl.ConnectionProperties.Add "Data Source", "MS ACCESS DATABASE"
tbl.ConnectionProperties.Add "User Id", "Admin"
tbl.ConnectionProperties.Add "Password", "1234"
tbl.ConnectionProperties.Add "Initial Catalog", "C:\SOS3000\SOS3000S.accdb"
Next tbl
CRViewer1.ReportSource = rpt
rpt.PrintOut False, 1
Set app = Nothing
Set rpt = Nothing
Set tbl = Nothing