Hello again!
Anyone who had an experience printing Accpac forms from a Windows service? I am able to print the forms from a windows form application but can't print it from the windows service. Connection between Windows service and Accpac was successfully established. Any thoughts? Below is my code:
Thanks!
Anyone who had an experience printing Accpac forms from a Windows service? I am able to print the forms from a windows form application but can't print it from the windows service. Connection between Windows service and Accpac was successfully established. Any thoughts? Below is my code:
Code:
Public Sub Print_OrderConf_Quote(ByVal docNum As String, ByVal docType As String, ByVal printerName As String, ByVal email As String)
Dim oAccpac As New clsAccpac
If Not oAccpac.ConnectToSession() Then Exit Sub
clsUtil.WriteToLog("Printing Order Confirmation for " & docNum)
Try
Dim menuID As String
Dim pgmID As String
Dim printDestination As Integer
Dim rpt As AccpacCOMAPI.AccpacReport
Dim printSetup As AccpacCOMAPI.AccpacPrintSetup
Dim rptName As String = ""
menuID = Space(6)
pgmID = Space(6)
printDestination = tagPrintDestinationEnum.PD_PREVIEW
Prepare_OECONF01_ini("OE")
Select Case docType
Case "Quote"
rptName = "OECONF01[OEQUOT01WR.RPT]"
Case "Order"
rptName = "OECONF01[OECONF01WR.RPT]"
End Select
rpt = oAccpac.mSession.ReportSelect(rptName, menuID, pgmID)
printSetup = oAccpac.mSession.GetPrintSetup(menuID, pgmID)
printSetup.DeviceName = printerName
'printSetup.OutputName = ""
printSetup.Orientation = 1
printSetup.PaperSize = 1
printSetup.PaperSource = 15
rpt.PrinterSetup(printSetup)
rpt.SetParam("PRINTED", "1") ' Report parameter: 4
rpt.SetParam("QTYDEC", "0") ' Report parameter: 5
rpt.SetParam("SORTFROM", docNum) ' Report parameter: 2
rpt.SetParam("SORTTO", docNum) ' Report parameter: 3
rpt.SetParam("SWDELMETHOD", 3) ' Report parameter: 2
rpt.SetParam("PRINTKIT", "1") ' Report parameter: 7
rpt.SetParam("PRINTBOM", "1") ' Report parameter: 8
If docType = "Order" Then
rpt.SetParam("SWPRINTONHOLD", "1") ' Report parameter: 9
rpt.SetParam("SERIALLOTNUMBERS", "1") ' Report parameter: 10
End If
rpt.NumOfCopies = 1
rpt.Destination = printDestination
rpt.PrintDir = ""
If rpt.PrintReport() Then
If docType = "Order" Then
clsUtil.WriteToLog("Order Confirmation for " & docNum & " was printed successfully.")
Else
clsUtil.WriteToLog("Quote for " & docNum & " was printed successfully.")
End If
Else
If docType = "Order" Then
clsUtil.WriteToLog("Failed to print order confirmation for " & docNum & ".")
Else
clsUtil.WriteToLog("Failed to print quote for " & docNum & ".")
End If
End If
Catch ex As Exception
clsUtil.ErrorHandler(ex.Message, "Print_OrderConf_Quote")
Finally
oAccpac.CloseSession()
End Try
End Sub
Thanks!