Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Pass a Parameter to Crystal Report from Accpac Macro

Status
Not open for further replies.

TLENTINE77

Programmer
Nov 26, 2003
3
US
Hi Everyone,

I am new to AccPac and I am trying to create a macro (within AccPac,using the COMAPI) that will display a form, gather criteria from the user and display a Crystal Report based on that criteria. I have copied the syntax from an existing macro, changed the name of the report that it was referencing, and changed the parameters to match the parameters in the new report. However, when I use the SetParams method it returns false and does not pass the parameter value to the report.

I'm thinking that I might not have the right information in the report ini file. Can anyone tell me what information needs to be entered in the ini file?

Thanks in advance
 
Here is an example of code that I have used. The parameters must be passed as strings so beware of any conversion issues, both in the macro and in the report.

Code:
Private Sub cmdProcess_Click()
 On Error GoTo ACCPACErrorHandler
    
    Dim PersonFrom As String, PersonTo As String
    Dim BegDate As String, EndDate As String
    Dim SepPage As Integer
    
    PersonFrom = Trim(cmbSalesFrom.Text)
    PersonTo = Trim(cmbSalesTo.Text)
    BegDate = Format(dateFrom.Value, "yyyymmdd")
    EndDate = Format(dateTo.Value, "yyyymmdd")
    If chkDifPage.Value = True Then SepPage = 1
    
    Dim CommisionReport As ACCPACXAPILib.xapiReport
    Set CommisionReport = CreateObject("ACCPAC.xapiReport")
    CommisionReport.Select Session, "ARSPCOMM", ""  'Selecting the report
    CommisionReport.SetParam "StartSP", PersonFrom 'feeding the parameters.
    CommisionReport.SetParam "EndSP", PersonTo
    CommisionReport.SetParam "StartDate", BegDate
    CommisionReport.SetParam "EndDate", EndDate
    CommisionReport.SetParam "Page", chkDifPage
    
    If optFile.Value = True Then CommisionReport.PrintDestination = PD_FILE
    If optHTML.Value = True Then CommisionReport.PrintDestination = PD_HTML
    If optPreview.Value = True Then CommisionReport.PrintDestination = PD_PREVIEW
    If optPrinter.Value = True Then CommisionReport.PrintDestination = PD_PRINTER
        
    CommisionReport.PrintReport 1
    
  Exit Sub

ACCPACErrorHandler:
  Dim Error As Variant

  If Errors.Count = 0 Then
    MsgBox Err.Description
  Else
    For Each Error In Errors
      MsgBox Error.Description
    Next
    Errors.Clear
  End If

  Resume Next

End Sub


Take Care,

zemp

"Show me someone with both feet on the ground and I will show you someone who can't put their pants on."
 
Thanks for the response. I have been trying to use something similar to the code that you posted, only using COMAPI instead of xAPI. Below is the code I've been trying to use, with the error handling and extra options removed for brevity:

Sub cmdPreview_Click()

Dim rpt As AccpacCOMAPI.AccpacReport
Dim strOrderNo as String

strOrderNo = Trim(Ucase(txtOrderNumber.Value))

Set rpt = ReportSelect("OEOrdSumShop", " ", " ")

rpt.SetParam "OrderNumber", strOrderNo

rpt.PrintReport

End Sub

I can't figure out why the parameter isn't being passed to the report. The report will come up and prompt me for the parameter value. The same code works for another report (different name of course, but the parameters are the same)
Do I have to make an entry in the oerpt.ini file for the report in order for it to work? Should I scrap the idea of using the COMAPI object and just use the xAPI object?
 
The code is taken from a macro. The Macro uses the xAPI report object and the other objects are COMAPI. You should be able to use them both as well.


Take Care,

zemp

"Show me someone with both feet on the ground and I will show you someone who can't put their pants on."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top