Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error after SelectPrinter Method 1

Status
Not open for further replies.

dpatrickcollins

Programmer
Nov 18, 2002
79
I am encountering an error using the SelectPrinter method using Crystal RDC version 9.0 Here is a snippet of my code:

Private Sub btnPrint_Click()
Dim p As Printer

For Each p In Printers
If p.DeviceName = Me.ddPrinters Then
Report.SelectPrinter p.DriverName, p.DeviceName, p.Port
Report.PrintOut True
End If
Next
End Sub

ddPrinters is a combobox which correctly evaluates to a printer on my system.

Upon executing the above code, it halts on the PRINTOUT method and states ERROR STARTING PRINT JOB. PLEASE CHECK YOUR PRINTER OR NETWORK CONNECTION.

Interestingly enough, the print window appears and shows that the correct printer is selected just before the error (the error is encountered when I press OK on the print window). Also, I have two installed printers that do not print to actual printers, one is called FAX and prints to the standard fax driver on Windows XP. The other prints to Acrobat Distiller (the print driver installed with Adobe Acrobat to generate .pdf files). These two printers do not encounter the error, but actual printers do.

Last of all, removing the SELECTPRINTER method eliminates the error. The report prints successfully to the default printer.

Any help would be GREATLY appreciated.
 
I tried your code snippet and got the same error. I think its because there is still work to do in the For Loop. Try this code; it works in my apps.

Dim prt As Printer
For Each prt In Printers
If prt.DeviceName = Trim(Form1.cboPrinters.Text) Then
Set Printer = prt
crRpt.SelectPrinter prt.DriverName, prt.DeviceName, prt.Port
crRpt.PaperOrientation = crPortrait
Exit For
End If
Next

crRpt.PrintOut True
 
You are absolutely correct! After submitting this to the folks at Crystal, they informed me that there is a bug with the SelectPrinter method that resets the PaperOrientation (to null, I believe). Thus, paper orientation must be reset to a valid value. The following line of code works as well:


Report.PaperOrientation = crDefaultPaperOrientation

Thanks for your answer. Where were you a week ago!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top