Link to home
Start Free TrialLog in
Avatar of dbscpm
dbscpm

asked on

VB Code to run a crystal Report to Screen

Hi
I think this is probably quite simple.  I have created a VB script to call an existing crystal report.  The script works but I can't get it to preview the report to screen, it will only print.  I have loaded the "Crystal Reports ActiveX Designer Run Time Library 11.5" references.

Script is as follows:

Sub RunCRReport()
   Dim CR As New CRAXDRT.Application
   Dim rep As CRAXDRT.Report
   Dim sFinYearStart, sFinYearEnd

   sFromDate = CDate("01/07/2020")

   sToDate = CDate("30/06/2021")

   Set rep = CR.OpenReport("C:\Data\Reports\Crystal\ReportName.rpt")


rep.ParameterFields(1).AddCurrentValue sFromDate  
rep.ParameterFields(2).AddCurrentValue sToDate  
rep.ParameterFields(3).AddCurrentValue "N"
rep.ParameterFields(4).AddCurrentValue "AUSTRALIA"

rep.Database.Tables(1).ConnectionProperties("Password").Value = "xxxxxx"
rep.ReadRecords
   
   rep.PrintOut (False)

End Sub

Any assistance is most appreciated.

Many thanks

Regards

David

Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Can you check if
report.Preview 

Open in new window

does the job ?
Try changing

rep.PrintOut (False)

to

rep.PrintOut promptUser:=False, numberOfCopy:=1
Avatar of dbscpm
dbscpm

ASKER

Thank you John and Martin.

I tried both your suggestions:

rep.Preview
  • This throws an error "Object does not support this property or method"

rep.PrintOut promptUser:=False, numberOfCopy:=1 
  • Does not preview, it outputs the the default printer in the report.


What hapens with this?
rep.PrintOut promptUser:=True
Avatar of dbscpm

ASKER

With rep.PrintOut promptUser:=True

the printer selection form displays allowing to select a printer but no option to preview to screen.  
As you can probably tell, I don't use Crystal Reports but look here.
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dbscpm

ASKER

Thanks Mike I'll give that a try.

I am using Crystal Reports 2013 Support Pack 5 (version 14.1.5.1501)


Does it print reports?

I haven't tried versions after CR XI R2 with VB6.  The report format hasn't changed so they should work,  You won't have the new features available.

Versions after CR 2008 do no come with the capability to build applications to run the reports (no SDK) was developed.  You can use Crystal for Visual Studio and build application in .Net to run reports.

mlmcc