Here is a script I use at a customer to print custom labels in shipping data entry. It requires a silent DSN or else it will pop up a MAS login prompt. Not sure where I got the original source - it was many years ago - there are some options commented out.
Dim App, RptFile, User, Comp, Pw, Dest, RptSelect
Dim Rept, Login, ExportFile, ParamFields, Year
Dim NumberOfCopies
'*********************************************************
' **** SET VARIABLES ********************************************************************************
'Report File: Change to the full path and file name
RptFile = ""\\server\acct\MAS 200\Version4.4\MAS90\Reports\Custom\ScriptLabelShipping.rpt""
'Export File: Change to the full path and file name
ExportFile = ""<full_path_to_export_file.csv>""
ParInvoice = Cstr(SO_Shipping_bus_InvoiceNo)
NumberOfCopies = inputbox (""Enter the number of labels to print"",""Number of Copies"",""1"")
' language VBScript
'
' panel variables
' SO_Shipping_bus_InvoiceNo
'
' system variables
' MAS_SCR_CMP : company code
' MAS_SCR_USR : user code
' MAS_SCR_MOD : module code
' MAS_SCR_DTE : current app date
' MAS_SCR_LIB : library
' MAS_SCR_PNL : panel
' MAS_SCR_OBJ : control [BT_LINK_x]
' MAS_SCR_CS : 1 if running Sage MAS 200 on client
' MAS_SCR_DBG : 1 to show script before and following execution
'
'Login Info, you may want to setup a dummy user for all of this.
'User = MAS_SCR_USR
'Comp = MAS_SCR_CMP
'PW = """" 'UserInput( ""Enter Password"" )
'Destination Export, Print or Preview - set it to 2 to Export, 1 to Print
Dest = 1
'
Set App = CreateObject (""CrystalRuntime.Application"")
Set Rept = App.OpenReport (RptFile)
Set objShell = CreateObject(""WScript.Shell"")
'RegLocate = ""HKEY_CURRENT_USER\SOFTWARE\ODBC\ODBC.INI\SOTAMAS90\""
'objShell.RegWrite RegLocate & ""UID"",USER
'objShell.RegWrite RegLocate & ""PWD"",PASSWORD
'objShell.RegWrite RegLocate & ""COMPANY"",COMP
Login = App.LogOnServerEx(""p2sodbc.dll"", ""ScriptLabel"")
'Login = App.LogOnServerEx(""p2sodbc.dll"", ""ScriptLabel"", , , , , ""DSN=SOTAMAS90; UID=""+User+""; PWD=""+PW+""; Company=""+Comp)
'Login = App.LogOnServerEx(""p2sodbc.dll"", ""ScriptLabel"", , , , , ""DSN=ScriptLabel; UID=label; PWD=script; Company=USR"")
' **** SET EXPORT OPTIONS ********************************************************************************
' **** FORMAT TYPE VALUES AVAILABLE
'crEFTNoFormat 0
'crEFTCrystalReport 1
'crEFTDataInterchange 2
'crEFTRecordStyle 3
'crEFTRichText 4
'crEFTCommaSeparated-Values 5
'crEFTTabSeparatedValues 6
'crEFTCharSeparatedValues 7
'crEFTText 8
'crEFTTabSeparatedText 9
'crEFTPaginatedText 10
'crEFTLotus123WKS 11
'crEFTLotus123WK1 12
'crEFTLotus123WK3 13
'crEFTWordForDOS 15
'crEFTQuattroPro50 17
'crEFTExcel21 18
'crEFTExcel30 19
'crEFTExcel40 20
'crEFTExcel50 21
'crEFTExcel50Tabular 22
'ODBC not permitted 23
'crEFTHTML32Standard 24
'crEFTExplorer32Extend 25
'crEFTNetScape20 26
' **** NOW ACTUALLY SET THE OPTIONS
Rept.ExportOptions.DiskFileName = ExportFile
Rept.ExportOptions.DestinationType = 1
Rept.ExportOptions.FormatType = 5 ' 5 IS FOR COMMA-SEPARATED FORMAT
Rept.ExportOptions.CharFieldDelimiter = """"
Rept.ExportOptions.CharStringDelimiter = """"
' **** HANDLE USER INPUT AND REPORT PARAMETERS **********************************************************
'batchNumber= UserInput( ""Enter Batch Number"" )
'WScript.Echo ""You entered: "" & batchNumber
'beginInvNumber= UserInput( ""Enter Beginning Invoice Number"" )
'WScript.Echo ""You entered: "" & beginInvNumber
'endInvNumber= UserInput( ""Enter EndingInvoice Number"" )
'WScript.Echo ""You entered: "" & endInvNumber
'Set ParamFields = Rept.ParameterFields
'Set Invoice = ParamFields.Item(1)
'Invoice.SetCurrentValue ParInvoice
'msgbox ParInvoice
Rept.ParameterFields.Item(1).SetCurrentValue Cstr(ParInvoice)
'Rept.ParameterFields.GetItemByName(""Invoice"").AddCurrentvalue ParInvoice
'Rept.ParameterFields.GetItemByName(""BegInvNbr"").AddCurrentvalue UserInput( ""Enter Beginning Invoice Number"" )
'Rept.ParameterFields.GetItemByName(""EndInvNbr"").AddCurrentvalue UserInput( ""Enter EndingInvoice Number"" )
' **** FINALIZE OPTIONS **********************************************************
If Not IsNull(Rept.ReportTitle) then
RptWindow = Rept.ReportTitle
else
RptWindow ""Crystal Reports""
end If
If Dest = 1 then
Rept.Printout false, Cint(NumberOfCopies)
End If
If Dest = 2 Then
Rept.Export(False)
End If
' **** AWAY WE GO **********************************************************
'set WshShell = WScript.CreateObject(""WScript.Shell"")
'While WshShell.AppActivate(RptWindow) = TRUE
'wscript.sleep 10000
'Wend
'Set WshShell=Nothing
Set Rept=Nothing
Set App=Nothing
Set objShell = Nothing
'WScript.Echo ""Label Printed""
' **** FUNCTIONS SECTION ****************************************************************************************
Function UserInput( myPrompt )
' This function prompts the user for some input.
' When the script runs in CSCRIPT.EXE, StdIn is used,
' otherwise the VBScript InputBox( ) function is used.
' myPrompt is the the text used to prompt the user for input.
' The function returns the input typed either on StdIn or in InputBox( ).
' Check if the script runs in CSCRIPT.EXE
If UCase( Right( WScript.FullName, 12 ) ) = ""\CSCRIPT.EXE"" Then
' If so, use StdIn and StdOut
WScript.StdOut.Write myPrompt & "" ""
UserInput = WScript.StdIn.ReadLine
Else
' If not, use InputBox( )
UserInput = InputBox( myPrompt )
End If
End Function