Joined: 17 Nov 2010
Location: Portugal
Online Status: Offline
Posts: 1
Topic: Copy Number Posted: 17 Nov 2010 at 1:24am
Hi experts,
In Sap 8.8 with Crystal Report, when printing a Invoice document I want to write diferent texts depending on the printed copy.
Ex I want to write 3 copies of an Invoice. In copy number 1 I want do write "Original", in copy number 2 I want to write "Duplicate" and in copy number 3 I want to write "Other"
The only way I now is coping the invoice layout 3 times and change the text that I want to write in each one. This is not a good solution because if I have to change something I have to change in the three layouts.
Is there any function "COPY NUMBER" ? Or how can I work around this situation?
I've tried many different angles to work around this problem and searched many different sites looking for a solution. I finally came up with this solution today. We have two methods that handle printing all crystal reports in our application - one if it is not displayed in a viewer on the screen and one if it is, so this didn't require a bunch of retrofitting all over our application. Essentially, what we do is display a print dialog box allowing the user to override the number of copies to print (and the printer), then loop through printing each copy of the report individually while altering the record selection formula slightly with benign criteria that indicates which copy number is being printed. Then I have a formula in each report (that needs to be sensitive to the copy number) that will extract the copy number out of the record selection formula, and deal with it accordingly. I don't have a need to handle more than 9 copies, so if you do, adjust the crystal formula accordingly.
Private Sub butPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles butPrint.Click
Try
If crv1.ReportSource.GetType Is GetType(ReportDocument) Then
Dim objReportDocument As ReportDocument = CType(crv1.ReportSource, ReportDocument)
Dim myPrinterSettings As System.Drawing.Printing.PrinterSettings = CheckValidPrinter("")
With myPrinterSettings
objReportDocument.PrintOptions.PrinterName = .PrinterName
objReportDocument.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.DefaultPaperSize
If Not .DefaultPageSettings.PaperSource Is Nothing Then
objReportDocument.PrintOptions.CustomPaperSource = .DefaultPageSettings.PaperSource
End If
Dim strSelection As String = objReportDocument.RecordSelectionFormula
For i As Integer = 1 To .Copies
If strSelection.Trim <> "" Then
objReportDocument.RecordSelectionFormula &= " AND"
End If
objReportDocument.RecordSelectionFormula &= " 'RXCopyNumber=" & i.ToString & "' = 'RXCopyNumber=" & i.ToString & "'"
objReportDocument.PrintToPrinter(1, .Collate, .FromPage, .ToPage)
objReportDocument.RecordSelectionFormula = strSelection 're-set it
Next
End With
Else
crv1.PrintReport()
If
Catch Ex As Exception
'Handle the exception
End Try
End Sub
Public Function CheckValidPrinter(ByVal p_strPrinterName As String, Optional ByVal p_iDefaultCopies As Integer = 1, Optional ByVal p_bCollate As Boolean = True) As PrinterSettings
Dim fwPrintSetting As New PrinterSettings
Dim strDefaultPrinterName As String = fwPrintSetting.PrinterName
Try
Dim nCnt As Integer
With fwPrintSetting
.Copies = CShort(p_iDefaultCopies)
.Collate = p_bCollate
For nCnt = 0 To (PrinterSettings.InstalledPrinters.Count - 1)
.PrinterName = System.Drawing.Printing.PrinterSettings.InstalledPrinters.Item(nCnt)
If .PrinterName = p_strPrinterName Then
If .IsValid Then
Return fwPrintSetting
End If
End If
Next
End With
Catch
End Try
Try
fwPrintSetting.PrinterName = strDefaultPrinterName
Dim objPrintDialog As New PrintDialog
With objPrintDialog
.PrinterSettings = fwPrintSetting
.ShowNetwork = True
.ShowHelp = True
If .ShowDialog = DialogResult.OK Then
Return .PrinterSettings
End If
End With
Catch
End Try
Return Nothing
End Function
Then, in each crystal report that needs to know the copy number, insert this function (I called it "CopyNumber")...
dim iLoc as number:
iLoc = instr(RecordSelection, "RXCopyNumber=")
if iLoc > 0 then
formula = tonumber(mid(RecordSelection,iLoc+13,1))
else
formula=0
end if
I also created another function to display custom text depending on the copy number (I called it "CopyText"). Alternately, you could change colors, formats, ...
if {@CopyNumber} = 1 then
"Copy #1"
else if {@CopyNumber} = 2 then
"Copy #2"
else if {@CopyNumber} = 3 then
"Copy #3"
else if {@CopyNumber} = 4 then
"Copy #4"
else if {@CopyNumber} = 5 then
"Copy #5"
else if {@CopyNumber} = 6 then
"Copy #6"
else if {@CopyNumber} = 7 then
"Copy #7"
else if {@CopyNumber} = 8 then
"Copy #8"
else if {@CopyNumber} = 9 then
"Copy #9"
else
""
I think I've included everything you need to do this - good luck, I hope it works for you like it did for me.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum