Automating transaction export using standard Crystal reports

SOLVED

Hi,

I was asked to create a custom service that will do the following:

1. Get Purchase Orders based on specific criteria

2. Export each Purchase Order using the standard Crystal Report file to a PDF document

Getting the purchase orders is easy enough to do, but how do I then send this data off to the Crystal report and export to PDF. It must be the Crystal report that was set up for this company as it has their approved look and feel already done.

I have looked at using Crystal Decisions in my code, but the report uses the POPORN.dll file as a data source and I am not entirely sure how to use this dll in code.

Another option would be to use the Accpac COM API, but there does not seem to be a lot of information or examples on using this.

Can anyone please point me in the right direction?

  • 0

    we use Logicity for automating Crystal Reports.  very easy to use.  We use it to automate all the sales team reports, alerts, monthly exports...  Anything that you would manually run through Crystal.

  • 0

    The challenge with that DLL is that it is a datapipe meaning that Sage 300 invokes functions in that DLL to pass a dataset to Crystal. You can't automate that unless you're automating Sage.

    If you're interested in using the COM API - which will allow you to do what you need - just record a macro of the process of sending a PO to PDF.  You'll have 99% of the code that you'll need. You'll be telling Sage to print the report to PDF and then you don't need to worry about the source of the data.

  • 0 in reply to Mike Cook

    And just to add, for options, Visual CUT.  Underpriced for what it can do.

    www.milletsoftware.com/Visual_CUT.htm

  • verified answer

    Here's some sample code that should get you moving in the right direction should you want to explore the COM API_Note - teh SQL calls are direct.  You can instead use view CS0120 (see sample below):

    Private Sub cmdMakePDFs_Click()

    Dim strRecords As Integer
    Dim strYear As String
    Dim strSQL As String
    Dim strWhere As String
    Dim strVendName As String
    Dim strVendorID As String
    Dim strRecNumber As Integer


    Dim rpt As AccpacCOMAPI.AccpacReport
    Set rpt = mAS.ReportSelect("APCPRST4A[APCPRST4A.RPT]", " ", " ")

    Dim rptPrintSetup As AccpacCOMAPI.AccpacPrintSetup
    Set rptPrintSetup = mAS.GetPrintSetup(" ", " ")

    rptPrintSetup.DeviceName = ""
    rptPrintSetup.OutputName = "USB001"
    rptPrintSetup.Orientation = 1
    rptPrintSetup.PaperSize = 1
    rptPrintSetup.PaperSource = 7
    rpt.PrinterSetup rptPrintSetup

    '---------------------------------------------------
    ' Loop through table and make a pdf for each record
    '---------------------------------------------------

    Set cnCBINDA = New ADODB.Connection

    cnCBINDA.Open strSQLConCBINDA

    strYear = Me.txtYear

    strSQL = "SELECT * FROM APCCS_YEAR"
    strWhere = " WHERE APCCS_YEAR.CNTYEAR = " & strYear & ""

    Set rsCBINDA = New ADODB.Recordset

    rsCBINDA.Open strSQL & strWhere & "", cnCBINDA, adOpenKeyset, adLockReadOnly
    strRecords = rsCBINDA.RecordCount

    strRecNumber = 0

    Do While rsCBINDA.EOF = False
    strVendName = UCase(Trim(rsCBINDA.Fields("VENDNAME")))
    strVendorID = Trim(rsCBINDA.Fields("VENDORID"))

    strRecNumber = strRecNumber + 1

    Me.Caption = "Processing " & strRecNumber & " of " & strRecords & " T4As"

    '----------------------
    ' New
    '----------------------
    rpt.SetParam "YEAR", Me.txtYear ' Report parameter: 5
    rpt.SetParam "FEDID", "106844053 RP0001" ' Report parameter: 5
    rpt.SetParam "VENDORID", strVendorID ' Report parameter: 5

    rpt.NumOfCopies = 1
    rpt.Destination = AccpacCOMAPI.tagPrintDestinationEnum.PD_FILE
    rpt.Format = AccpacCOMAPI.tagPrintFormatEnum.PF_PDF
    rpt.PrintDir = Me.txtPath & "\" & strVendName & "_" & txtYear & ".pdf"

    rpt.PrintReport

    rsCBINDA.MoveNext
    Loop

    rsCBINDA.Close

    MsgBox "T4A File creation complete", vbInformation, "Create PDF"

    Me.Caption = "T4A file creation complete"

    End Sub

    CS0120 code:


    Dim viewCSQRY2 As AccpacCOMAPI.AccpacView
    Dim viewCSQRY2Fields As AccpacCOMAPI.AccpacViewFields
    DBLnk.OpenView "CS0120", viewCSQRY2
    Set viewCSQRY2Fields = viewCSQRY2.Fields

    viewCSQRY2.Browse strSQLQuery, True
    viewCSQRY2.InternalSet (256)

    Do While viewCSQRY2.Fetch = True

      Do Stuff

    Loop

  • 0

    Thanks for all your valuable answers. The issue with using software like Visual Cut or Logicity is that it is not as customizable as I would like. I need to get certain transactions with specific criteria and then use certain fields as variables to store the exported files.

    For instance, exporting Purchase orders, must save to a specific folder structure and file name. The folder structure would Purchase orders\Vendor ID\PO Number.pdf

    From what I've seen so far, Visual Cut and Logicity does not have this level of config (unless I've missed that part).

    It looks like I will have to attempt using the COM API in conjunction with recording macros.

  • Thanks for the sample code. A few questions here:

    1. On this line: Set rptPrintSetup = mAS.GetPrintSetup(" ", " "), where does mAS come from. I don't see any declarations in your sample. Or am I missing something?

    2. In my code, AccpacCOMAPI.AccpacPrintSetup has no GetPrintSetup method. Could it be that I don't have the right version of the COMAPI?

    3. I also don't see a method for ReportSelect. Maybe the same as the previous point (wrong version of COMAPI)?

  • 0 in reply to Eddie Willcox_1

    Nevermind... I am supposed to open a session first. My bad. It's been a tough journey

  • 0 in reply to Eddie Willcox_1

    PrintBoss handles that very gracefully.  You can even configure it to save to the logged-in user's folder.  It will sing and dance for you.

  • 0 in reply to Eddie Willcox_1

    if you have the premium version of Logicity (it's not that much) you can use variables in the file names.  It really all depends on how deep you need it to go.  I use it for exporting sales people sales reports to their separate files.  again, your situation may be different.  if you can figure it out with coding then you are good to go and no additional software needed.   If you are just using it to store PO's once you send them, then maybe PrintBoss is the way to go.

  • 0 in reply to Eddie Willcox_1

    The challenge with these external tools is that they aren't going to work with the datapipe reports. You need to automate Sage, first, to generate the report. You can tell Sage to create a PDF and then file that PDF as required.

    Since you're also wanting to file the PDFs based on PO data then, once you have the routine working for generating the PDF for a single PO, you can write a routine that travels through the new POs and pass along the vendor and PO number to your PDF routine.