vbacrystal-reportsexcelcrystal-reports-xi

Run and Print Crystal Report from VBA


I want to automate CR report printing from VB/VBA.

I have Crystal Reports XI Developer installed and .rpt files (some requiring parameters) to run and send to a printer, without requiring any user intervention.

Now, I stuck at the very first step, adding the correct libraries. There are probably about 50 libraries or so that start with Crystal Reports or Business Objects, and I have no idea which ones I need.

Any pointers to get me started would be appreciated.

Thanks Martin


Solution

  • Ok, I solved my problem.

    CRAXDRT.dll aka Crystal Reports ActiveX Designer Run Time Library is the correct library.

    Here is some sample code:

    Dim CR As New CRAXDRT.Application
    Dim rep As CRAXDRT.Report
    Set rep = CR.OpenReport(Range("CRpath"))
    rep.ParameterFields(1).AddCurrentValue "Boston"
    rep.ParameterFields(2).AddCurrentValue "Cars"
    rep.Database.Tables(1).ConnectionProperties("Password").Value = "pw12345"
    rep.ReadRecords
    rep.PrintOut promptUser:=False, numberOfCopy:=1 ' promptUser:=True doesn't work