1. In your CR Viewer form. In the "properties" window, change "EnablePrintButton" to "false"
2. Now you must add a print command button. Call it "cmdPrint"
3. Now add the following code to your CR Viewer form:
[color red]Private Sub cmdPrint_Click()
[color green] '*** following code can be manipulated ***[/color]
If (Len(sPrintMsg) > 0) Then
MsgBox sPrintMsg, , App.ProductName & " Print Request"
sPrintMsg = ""
End If
[color green] '*** Object reference to the VB Printer Object ***[/color]
Load frmPrinterSetup
frmPrinterSetup.Show
End Sub[/color]
4. Create new form named "frmPrinterSetup"
- This form is loosely based off of sample code from CR8. It can be found in:
[color blue] C:/Seagate Software/Samples/Code/Visual Basic/Printer Settings/*.*[/color]
- It is form frmMain.
5. Add the following code to "frmPrinterSetup":
[color red]Private Sub Form_Load()
[color green] '*** Return the Printer Information saved with the Report ***
'*** Set page to show the default printer ***[/color]
If (cmbPrinters.List(cmbPrinters.ListIndex) = spaces) Then
cmbPrinters.Text = Printer.DeviceName
End If
lblPrinterDriver2.Caption = Printer.DriverName
lblPrinterPort2.Caption = Printer.Port
[color green] '*** Display the Paper Size of the report ***[/color]
Select Case MyRpt.PaperSize
Case 1
TxtPaperSize.Text = "Letter, 8 1/2"" x 11"""
Case 2
TxtPaperSize.Text = "Letter Small, 8 1/2"" x 11"""
Case 3
TxtPaperSize.Text = "Tabloid, 11"" x 17"""
Case 4
TxtPaperSize.Text = "Ledger, 17"" x 11"""
Case 5
TxtPaperSize.Text = "Legal, 8 1/2"" x 14"""
Case 6
TxtPaperSize.Text = "Statement, 5 1/2"" x 8 1/2"""
Case 7
TxtPaperSize.Text = "Executive, 7 1/2"" x 10 1/2"""
Case 8
TxtPaperSize.Text = "A3, 297 x 420 mm"
Case 9
TxtPaperSize.Text = "A4, 210 x 297 mm"
Case 10
TxtPaperSize.Text = "A4 Small, 210 x 297 mm"
Case 11
TxtPaperSize.Text = "A5, 148 x 210 mm"
Case 12
TxtPaperSize.Text = "B4, 250 x 354 mm"
Case 13
TxtPaperSize.Text = "B5, 182 x 257 mm"
Case 14
TxtPaperSize.Text = "Folio, 8 1/2"" x 13"""
Case 15
TxtPaperSize.Text = "Quarto, 215 x 275 mm"
Case 16
TxtPaperSize.Text = "10"" x 14"""
Case 17
TxtPaperSize.Text = "11"" x 17"""
Case 18
TxtPaperSize.Text = "Note, 8 1/2"" x 11"""
Case 19
TxtPaperSize.Text = "Envelope #9, 3 7/8"" x 8 7/8"""
Case 20
TxtPaperSize.Text = "Envelope #10, 4 1/8"" x 9 1/2"""
Case 21
TxtPaperSize.Text = "Envelope #11, 4 1/2"" x 10 3/8"""
Case 22
TxtPaperSize.Text = "Envelope #12, 4 1/2"" x 11"""
Case 23
TxtPaperSize.Text = "Envelope #14, 5"" x 11 1/2"""
Case 24
TxtPaperSize.Text = "C size sheet"
Case 25
TxtPaperSize.Text = "D size sheet"
Case 26
TxtPaperSize.Text = "E size sheet"
Case 27
TxtPaperSize.Text = "Envelope DL, 110 x 220 mm"
Case 28
TxtPaperSize.Text = "Envelope C5, 162 x 229 mm"
Case 29
TxtPaperSize.Text = "Envelope C3, 324 x 458 mm"
Case 30
TxtPaperSize.Text = "Envelope C4, 229 x 324 mm"
Case 31
TxtPaperSize.Text = "Envelope C6, 114 x 162 mm"
Case 32
TxtPaperSize.Text = "Envelope C65, 114 x 229 mm"
Case 33
TxtPaperSize.Text = "Envelope B4, 250 x 353 mm"
Case 34
TxtPaperSize.Text = "Envelope B5, 176 x 250 mm"
Case 35
TxtPaperSize.Text = "Envelope B6, 176 x 125 mm"
Case 36
TxtPaperSize.Text = "Envelope, 110 x 230 mm"
Case 37
TxtPaperSize.Text = "Envelope Monarch, 3 7/8"" x 7 1/2"""
Case 38
TxtPaperSize.Text = "Envelope, 3 5/8"" x 6 1/2"""
Case 39
TxtPaperSize.Text = "U.S. Standard Fanfold, 14 7/8"" x 11"""
Case 40
TxtPaperSize.Text = "German Standard Fanfold, 8 1/2"" x 12"""
Case 41
TxtPaperSize.Text = "German Legal Fanfold, 8 1/2"" x 13"""
Case 256
TxtPaperSize.Text = "User-defined"
Case Else
TxtPaperSize.Text = "Default"
End Select
[color green] '*** Display the Paper Orientation of the report ***[/color]
Select Case MyRpt.PaperOrientation
Case crLandscape
[color green] '*** Report is set to "Landscape" orientation ***[/color]
optLandscape.Value = True
Case Else
[color green] '*** Default to "Portrait" orientation ***[/color]
optPortrait.Value = True
End Select
[color green] '*** Display the Printer Duplex of the report ***[/color]
optDDefault.Value = True
[color green] '*** Return all of the Printers that are installed on the target machine ***[/color]
For Each mPrinter In Printers
cmbPrinters.AddItem mPrinter.DeviceName
lstDeviceName.AddItem mPrinter.DeviceName
lstDriverName.AddItem mPrinter.DriverName
lstPort.AddItem mPrinter.Port
Next
End Sub
Private Sub cmbPrinters_Click()
[color green] '*** Set the printer to the user default Device ***
'*** if no printer was selected in the combo box ***[/color]
If (cmbPrinters.List(cmbPrinters.ListIndex) = spaces) Then
cmbPrinters.Text = Printer.DeviceName
End If
[color green] '*** Set the printer to the user default Driver ***
'*** if no printer was selected in the combo box ***[/color]
If (lstDriverName.List(cmbPrinters.ListIndex) = spaces) Then
lblPrinterDriver2.Caption = Printer.DriverName
Else
lblPrinterDriver2.Caption = lstDriverName.List(cmbPrinters.ListIndex)
End If
[color green] '*** Set the printer to the user default Port ***
'*** if no printer was selected in the combo box ***[/color]
If (lstPort.List(cmbPrinters.ListIndex) = spaces) Then
lblPrinterPort2.Caption = Printer.Port
Else
lblPrinterPort2.Caption = lstPort.List(cmbPrinters.ListIndex)
End If
End Sub
Private Sub cmdOK_Click()
[color green] '*** Set the printer to the user default Device ***
'*** if no printer was selected in the combo box ***[/color]
If (cmbPrinters.List(cmbPrinters.ListIndex) = spaces) Then
pname = Printer.DeviceName
Else
pname = cmbPrinters.List(cmbPrinters.ListIndex)
End If
[color green] '*** Set the printer to the user default Port ***
'*** if no printer was selected in the combo box ***[/color]
If (lstPort.List(cmbPrinters.ListIndex) = spaces) Then
pport = Printer.Port
Else
pport = lstPort.List(cmbPrinters.ListIndex)
End If
[color green] '*** Set the printer to the user default Driver ***
'*** if no printer was selected in the combo box ***[/color]
If (lstDriverName.List(cmbPrinters.ListIndex) = spaces) Then
pdriver = Printer.DriverName
Else
pdriver = lstDriverName.List(cmbPrinters.ListIndex)
End If
[color green] '+++++++++++++ All the following attributes MUST be done +++++++++++++
'+++++++++++++ after the printer has been selected +++++++++++++
'*** Set the Orientation of the Report ***[/color]
If (optLandscape = True) Then
[color green] '*** "Landscape" Orientation Selected ***[/color]
MyRpt.PaperOrientation = crLandscape
ElseIf (optPortrait = True) Then
[color green] '*** "Portrait" Orientation Selected ***[/color]
MyRpt.PaperOrientation = crPortrait
Else
[color green] '*** Default Orientation Selected ***[/color]
MyRpt.PaperOrientation = crDefaultPaperOrientation
End If
[color green] '*** Set the Duplex of the Report ***[/color]
If (optDNone = True) Then
[color green] '*** Selection is 1 [NONE] ***[/color]
MyRpt.PrinterDuplex = crPRDPSimplex
ElseIf (optDLong = True And optPortrait = True) Or _
(optDShort = True And optLandscape = True) Then
[color green] '*** Selection is 2 [LONG SIDE] ***[/color]
MyRpt.PrinterDuplex = crPRDPVertical
ElseIf (optDShort = True And optPortrait = True) Or _
(optDLong = True And optLandscape = True) Then
[color green] '*** Selection is 3 [SHORT SIDE] ***[/color]
MyRpt.PrinterDuplex = crPRDPHorizontal
[color green] 'Else (*** Selection is [DEFAULT] ***)
'MyRpt.PrinterDuplex = crPRDPDefault[/color]
End If
[color green] '*** Sends the Report to the Printer ***[/color]
Unload Me
MyRpt.PrintOut
End Sub
Private Sub cmdCancel_Click()
Unload frmPrinterSetup
End Sub[/color]
NOTES:
Obviously this is a crude representation of what I did, but enough to get you started. You can play with it to do many things. You can even change the code to be able to change paper size and orientation! It currently defaults to whatever is set in the Crystal Report DSR. My CR Viewer is also set up in this example to handle multiple Crystal Reports with the one form. So your coding may have to be tweaked. I hope this helps! You may email me with questions (please be patient for an answer...)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.