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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting the printer and printing from Crystal Reports via Foxprow 1

Status
Not open for further replies.

PatMcLaughlin

Programmer
Dec 10, 2010
97
US
I am using Visual Foxprow9 and attempting to print a report generated in Crystal Reports 9 to a specific (chosen at runtime) printer.
Defined in prior code:
lcReport = report name
lcPName = printer to print report to (These will be available in the Printers defined and attached to the computer)
tnCopies = the number of copies to print

loCrystal=CreateObject("CrystalRuntime.Application")
loReport=loCrystal.OpenReport("c:\vfp\ka\CrystalReports\" + lcReport + ".rpt",1)
loReport.SetPrinter((lcPName), (lcPName), "")
loReport.PaperOrientation = 1
loReport.DisplayProgressDialog = False
loReport.PrintOut(False, (tnCopies))

When the 'SetPrinter' line runs, I get an error msg ("ole error code 0x80020006: unknown name")

I have also tried loReport.SelectPrinter without success.
If I eliminate this line, it will print without error to the default printer. Any Ideas how I can select a printer?
 
Is lcPName defined? Empty? .F.?

If you were to try using this:
SET PRINTER TO NAME GETPRINTER()
which is a VFP command, you should be able to set the printer beforehand.
Since you're using Crytal syntax though, you may be better off asking the question in a Crystal Reports forum.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
lcPName = printer to print report to (These will be available in the Printers defined and attached to the computer)

the Printers defined how/where?
Are ALL workstations configured to 'see' the same list of printers?

Could you be trying to print to a printer which is not defined within a given workstation?

To find the printers which have been defined into any individual workstation you can put the list of printers into an array with something like:
Code:
* -- Use APRINTERS() To Determine What Printers Available --
=APRINTERS(gaPrinters)

Once you have that list (and it might not be the same for ALL workstations), you can use the values in the list as needed.

By using that approach you will not try to print to a printer which is not defined within a workstation.

Good Luck,
JRB-Bldr
 
This is where I have set the Printer...
tcPrinter is supplied by the user in prior code.
netprint is a table within the Foxprow program which lists all available printers.

To answer the questions about whether they are defined on all workstations, There is only one workstation that runs this program and it is fed by a text file from the workstations which defines all variables so yes the printer is defined. The following code verifies that the printer has been defined before it creates the variable lcPName. When found, it continues... If not it bails out of the program after it notifies me of the problem. I added the 'Set Printer to Name' as suggested which seems to work until I get to the final line in the Crystal Code...

loReport.PrintOut(False, (tnCopies))

where I get the error... "OLE error code 0x80020005: Type mismatch."
I tried inserting a 1 in place of tnCopies with the same result.

Sample Printer code:

Select netprint
Seek tcPrinter && Name of Printer specified for use
If Found() THEN
lcPName = Alltrim(netprint.queue)
SET PRINTER TO NAME (lcPName)
Else
Do WRITELOG With "[ERR] Printer name invalid -" + lcPrinter
COPY TO ('c:\printerlist.csv') TYPE DELIMITED
DO SIMPEM01 WITH "wilbiradmin@winnebagoind.com", "dba@winnebagoind.com", "Printer not mapped correctly in PRTPDF01", "", "", "KA", "c:\printerlist.csv"
llError = .T.
Endif
 
Pat,

A couple of points ....

First, I think you need to call SelectPrinter, not SetPrinter.

Second, you mustd pass the name of the printer driver, not the name of the printer. In most cases, it will be the same, but not necessarily.

Perhaps you'd like to try the above, and see what difference it makes.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
If neither loReport.SetPrinter(..) nor loReport.SelectPrinter() works, there is something with the Crystal installation, perhaps, at least the problem is in the Crystal OLE object.

The line SET PRINTER TO NAME (lcPName) working shows the printer exists, but wil not help, as it only sets what printer VFP uses to print, not the default windows printer or what other applications or the Crystal OLE class uses to print.

If you can print to default printer, you can set that default printer via Windows API like this:

Code:
DECLARE INTEGER GetDefaultPrinter IN winspool.drv;
    STRING  @ pszBuffer,;
    INTEGER @ pcchBuffer

DECLARE INTEGER SetDefaultPrinter IN winspool.drv;
    STRING pszPrinter

lnBufferSize = 250
lcDefaultPrinter = Space(lnBufferSize)
 
= GetDefaultPrinter(@lcDefaultPrinter, @lnBufferSize)
lcDefaultPrinter = Left(lcDefaultPrinter,lnBufferSize-1)

=SetDefaultPrinter(lcPName)
*.... print via Crystal

* reset the default printer
=SetDefaultPrinter(lcDefaultPrinter)

Bye, Olaf.
 
And if you also can't set and reset the default printer, then it's perhaps just a permission issue, not every user can change the printer. Crystal might do exactly the same thing and fails doing it due to missing permissions.

Bye, Olaf.
 
Olaf, your post gave me what I wanted exactly! Thanks to all who helped!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top