Passing a parameter to Crystal Reports using a button script

SUGGESTED

Hi All,

    I have created a new report that is launched from a button script.  I have one thing left to accomplish & the syntax is killing me.   Several things to get "out of the way", this is being done is Sage 2015 Premium.  What we have wound up doing is installing the client for 4.50 on the workstations so the "old" runtimes are available.   There is an existing report that works fine.  This report works fine except I need to pass a parameter (not a report selection - it will be used as a secondary filter and for display)    The report finds items that are in the same "category" (a udf).  The Parameter will be used to display the item code that the report was being called from (It runs from a line on a sales Order) as well as filter the records to items were the cost is within a percentage of the cost of the called item.

The error that I get is Expected identifier.    I have to say that I wish there was something that explained how to format the variables when using them, it is a constant issue for me.. 

All that out of the way, here is the script:

Dim App, RptFile, RptWindow, User, Comp, Pw, Dest, RptSelect, RptSelect1, RptSelect2
Dim Rept, Login, ExportOpt, DSNstring, DBOpt
User = "ads"
Comp = MAS_SCR_CMP
PW = "Acutedata8!"

'Report File: Change to the full path and file name
RptFile = "\\mas02\Sage\Sage 100 Premium ERP\MAS90\Reports\AltItemsCUSTOM.rpt"

'Destination Print or Preview, set it to 1 for Print and 0 to Preview
Dest = 0

'Report Selection
RptSelect = _
"{CI_Item.UDF_PROD_CATEGORY} = '"+SO_SalesOrderDetail_bus_UDF_PROD_CATEGORY+"'"

'RptSelect1 = ("SO_SalesOrderDetail_bus_ItemCode$")
'RptSelect2 = ("SO_SalesOrderDetail_bus_UDF_PROD_CATEGORY$")

'Set objShell = CreateObject("WScript.Shell") 'not needed for SQL database nlr/dsd '12/22/15
'RegLocate = "HKEY_CURRENT_USER\SOFTWARE\ODBC\ODBC.INI\SOTAMAS90\" 'not needed for SQL 'database nlr/dsd 12/22/15
'objShell.RegWrite RegLocate & "UID", User not needed for SQL database nlr/dsd '12/22/15
'objShell.RegWrite RegLocate & "PWD", PW 'not needed for SQL database nlr/dsd 12/22/15
'objShell.RegWrite RegLocate & "COMPANY", Comp 'not needed for SQL database nlr/dsd '12/22/15
'Set objShell = Nothing 'not needed for SQL database nlr/dsd 12/22/15

Set App = CreateObject("CrystalRuntime.Application")
'Login = App.LogOnServerEx("p2sodbc.dll", "SOTAMAS90") 'not needed for SQL database nlr/dsd 12/22/15

Set Rept = App.OpenReport (RptFile)

Rept.ParameterFields.Item(1).(""&SO_SalesOrderDetail_bus_ItemCode&"")  'THIS IS THE PROBLEM LINE

Set ExportOpt = Rept.ExportOptions
Set DBOpt = Rept.Database

ExportOpt.FormatType = 31
ExportOpt.DestinationType = 1
ExportOpt.PDFExportAllPages = True
ExportOpt.DiskFileName = "\\mas02\Sage\Sage 100 Premium ERP\MAS90\Reports\AltItem_" & MAS_SCR_USR & ".pdf"

If Not Isnull(RptSelect) then
Rept.RecordSelectionFormula = RptSelect
'else
End if

RptWindow = "Alternate Item Report"

if Dest = 1 then
Rept.PrintOut
else
Rept.Export False
end if

Dim SH
PDF = ""
Set SH = CreateObject("WScript.Shell")
PDF = "\\mas02\Sage\Sage 100 Premium ERP\MAS90\Reports\AltItem_" & MAS_SCR_USR & ".pdf"
'retVal = oScript.DebugPrint(PDF)
SH.Run(Chr(34) & PDF & chr(34))
Set SH = Nothing

  • 0

    I'm not sure if this will help, but this is what worked for me in the past:

    oRpt.ParameterFields.GetItemByName("SELECT WORK CENTER").AddCurrentvalue "ACC"  'use parameter name from report

    where "SELECT WORK CENTER" is the full name of the report parameter, and "ACC" is the value I want to pass in.  Obviously, you'd have to change the second part to a variable name.

    Hope it helps.

    Hollie

  • 0 in reply to hyanaga

    Hi Hollie,  I have tried that version as well. The problem is HOW to include the variable.  I have seen examples where it is done by  ""&VARIABLE&"",  and '"+VARIABLE+"' and 'VARIABLE' and I have seen others.  None work...   

  • 0
    SUGGESTED

    Tried everything I could think of and finally this  worked this time.  I had tried formatting like this in the other parameter declaration:

    Rept.ParameterFields.Item(1).(SO_SalesOrderDetail_bus_ItemCode)   and it gave me an error.   But like this it worked


    Rept.ParameterFields.GetItemByName("ItemCode").AddCurrentValue (SO_SalesOrderDetail_bus_ItemCode)

    This is the part of scripting that drives me crazy - the way to declare items seems to be very random.  Wish there was something that could explain the logic of this since it took me several days to brute force though this. I had the correct code but could not get it to recognize the variable.   Not of my reference material addresses this and none of the writeups talked about this part of the code.   Either that or I have gone completely blind in my old age..