Button to run AP Aging from Vendor

SOLVED

I created a button on the Vendor Maintenance screen that runs the AP Aging report.  I pass in the AP Division and Vendor numbers, but I can't get the report to filter by those values.  (Want to run the Aging for the Vendor displayed, like the Sage button does in Customer Maintenance.)

I suspect it is the "Tag$" syntax that is incorrect.  Here is my script:

strSelect = AP_Vendor_bus_APDivisionNo & AP_Vendor_bus_VendorNo
oARReport = oSession.GetObject("AP_AgedInvoiceReport_ui")
Set oARReport = oSession.AsObject(oARReport)

retval = oARReport.SelectReportSetting("STANDARD")
retval = oARReport.SetKeyValue("ReportSetting$","STANDARD")
retval = oARReport.SetKeyValue("RowKey$","1")
retval = oARReport.SetKey()
retVal = oARReport.SetValue("SelectField$", "Vendor Number")
retVal = oARReport.SetValue("SelectFieldValue$", "Vendor Number")
'retVal = oARReport.SetValue("Tag$", "TABLE=AP_Vendor;COLUMN=APDivisionNo$,VendorNo$;")   'incorrect syntax?
retVal = oARReport.SetValue("Tag$", "TABLE=AP_Vendor;COLUMN=APDivisionNo$;")     'tried setting it in 2 lines - no luck
retVal = oARReport.SetValue("Tag$", "TABLE=AP_Vendor;COLUMN=VendorNo$;")
retVal = oARReport.SetValue("Operand$", "=")
retVal = oARReport.SetValue("Value1$", strSelect)
retVal = oARReport.Write

retVal = oARReport.ProcessReport("PREVIEW")
retVal = oSession.DropObject("AP_AgedInvoiceReport_rpt")

Does anyone know what I'm doing wrong?  Thanks!

Hollie

  • +1
    verified answer

    You need the SetValue on the "KeyReference$" field in addition to several other fields that make up the primary key in SY_ReportSelection.

    These key fields are ModuleCode$+CompanyKey$+ReportID$+ReportSetting$+RowKey$

    So this should work for you.


    sReportSetting = "STANDARD"
    retval = oARReport.SelectReportSetting(sReportSetting)
    retval = oARReport.SetKeyValue("ModuleCode$", oSession.ModuleCode)
    retval = oARReport.SetKeyValue("CompanyKey$", oSession.CompanyKey)
    retval = oARReport.SetKeyValue("ReportID$", oARReport.ReportID)
    retval = oARReport.SetKeyValue("ReportSetting$",s ReportSetting)
    retval = oARReport.SetKeyValue("RowKey$", "00001")
    retval = oARReport.SetKey()
    retVal = oARReport.SetValue("SelectField$", "Vendor Number")
    retVal = oARReport.SetValue("SelectFieldValue$", "Vendor Number")
    retVal = oARReport.SetValue("KeyReference$", "<APDivisionNo$+VendorNo$>") ' Fields must be enclosed in <>.
    retVal = oARReport.SetValue("Tag$", "TABLE=AP_Vendor;")
    retVal = oARReport.SetValue("Operand$", "=")
    retVal = oARReport.SetValue("Value1$", strSelect)
    retVal = oARReport.Write


    If you have criteria on more than one field, you need to repeat the above code again but increment the "RowKey$" value by one.

  • 0 in reply to David Speck

    Thank you!  I believe had it configured this way for a while, and discovered that this works - if the vendor has any open invoices.  However, if the vendor has no open invoices, it does not return the usual "Data is not selected for report printing" message.  It doesn't show anything, so the user will not know there is nothing open.  Is there any way around that?

    This may work - I will check.  

  • +1 in reply to hyanaga
    verified answer

    set the oARReport.LastErrorMsg to "" right before calling ProcessReport. After ProcessReport, if oARReport.LastErrorMsg is not blank and not "0" or if retVal is not 1, then display it to the user. Something like this should work.


    oARReport.LastErrorMsg = ""
    retVal = 0 : retVal = oARReport.ProcessReport("PREVIEW")
    If retVal <> 1 Then oSession.AsObject(oSession.UI).MessageBox "", "Unable to process report." & vbCrLf & "Last Error Msg: " & oARReport.LastErrorMsg


  • 0 in reply to David Speck

    Brilliant.  Thank you again, this is exactly what we are looking for!

  • 0 in reply to David Speck

    Just an update on this as another project revealed some important details regarding the "KeyReference$" and "Tag$" values that need to be set. 

    When dealing with a multi-part key, like AP_Vendor, you must set the "KeyReference$" like I did in the original example.

    For a single-part key, like CI_Item, you can set "KeyReference$" to "" (blank).

    The "Tag$" value should always contain the "Table=" and either "Column=" for single-part keys or "KeyReference=" for multi-part keys with the fields enclosed in "<" and ">".

    The "Tag$" for a single-part key should look like this.


    retVal = oARReport.SetValue("Tag$", "TABLE=CI_Item;COLUMN=ItemCode$")


    The "Tag$" for a multi-part key should look like this.


    retVal = oARReport.SetValue("Tag$", "TABLE=AP_Vendor;KEYREFERENCE=<APDivisionNo$+VendorNo$>;")


  • 0 in reply to David Speck

    Hey David,

    Using this code, does this work with just a Sage 100 install, or does the Crystal Reports application need to be

    installed on the pc running the report.

  • 0 in reply to sevendogzero

    It should work on any workstation with the Sage 100 Workstation installed since it uses the same UI class objects that sage 100 internally uses to run reports from the menus.