I have a report that needs to be printed out to two different windows
printers without operator intervention. After beating my head against
many brick walls I finally succeeded in building a routine that
successfully does it.
I built the routine as a paramaterized expansion of the code found here:
http://support.microsoft.com/kb/133163/EN-US/
To minimize bloody foreheads among us in the future, I've included the
code in this email.
The tricky bit is to create a dummy report and then for each printer you
wish to save the printer information as follows:
1) Set one of your printers as the default in the windows control panel,
Printers and Faxes (printer settings).
2) Open your dummy report (or the report you're trying to dup, it don't
matter)
3) Select "Report", click on "Printer Environment" (click on it twice
if it's already checked)
4) Close the report (Save changes = YES)
and reopen the FRX file: USE <myreport>.FRX
5) Locate the record with ObjType = 1 and ObjCode = 53
6) Save the printer attributes to a text file:
COPY MEMO expr TO <PrintFile.txt>
where printfile is a descriptive name for your printer attributes
Repeat for any other printers you wish to use.
----------------------------
In your report routine make sure you've got the report file selected and
call the print routine as follows:
DO PrintTwice WITH <YourReportName>, <PrintFile1.txt>, <copies1>,
<PrintFile2.txt>, <copies2>
Where <YourReportName> is the report filename (and path if necessary)
WITHOUT ".FRX"
<printfile1.txt> and <printfile2.txt> are the print attribute
files created above
<copies1> and <copies2> are the number of copies to be
printed -- INTEGER Numeric
The PrintTwice routine will print out "copies1" copies of the report to
the first printer, "copies2" copies to the 2nd printer and then reset
your VFP default printer to the first printer.
Cheers;
Chet
--------------------------------------------------------------------
*-- ******************************************
*-- Print out a report to 2 different printers
*-- ******************************************
PARAMETERS lcReport, lcPrintFile1, lnCopy1, ;
lcPrintFile2, lnCopy2
*-- Save the report file location!
lnSelect = SELECT()
*-- Setup to print to first printer
SELECT 0
USE (lcReport + '.frx') && Open the FRX as a table
LOCATE FOR Objtype = 1 AND Objcode = 53 && find the record that holds
** the printer information. For more information on the Table
Structure
** of an .FRX file, see 'Table Structures of Table Files' in
Help.
REPLACE Tag WITH "" && Remove any Printer codes that may be stored in
** the Tag memo
REPLACE Tag2 WITH "" && Remove any Printer codes that may be stored in
** the Tag2 memo
APPEND MEMO Expr FROM "&lcPrintFile1." OVERWRITE && Replace any printer
** setting already there with the first printer's settings
*-- Set Number of Copies
DO l_setCopies WITH lnCopy1
*-- Extract the printer name and set printer to name
lcPrinter1 = MLINE(expr, 2)
lcPrinter1 = ALLTRIM(STRTRAN(lcPrinter1, "DEVICE=", ""))
USE
*-- Print to 1st Printer
SET PRINTER TO NAME "&lcPrinter1."
SELECT (lnSelect)
REPORT FORM "&lcReport" TO PRINTER NOCONSOLE && Send the report to the
** HP IIID printer using the printer attributes specified in the
** Expr memo field.
*-- *****************************
*-- Setup to print to 2nd printer
SELECT 0
USE (lcReport + '.frx') && Open the FRX as a table
LOCATE FOR Objtype = 1 AND Objcode = 53 && find the record that holds
** the printer information
APPEND MEMO Expr FROM "&lcPrintFile2." OVERWRITE && Replace any printer
** setting already there with the Panasonic KX-P1180 Settings
*-- Set Number of Copies
DO l_setCopies WITH lnCopy2
*-- Extract the printer name and set printer to name
lcPrinter2 = MLINE(expr, 2)
lcPrinter2 = ALLTRIM(STRTRAN(lcPrinter2, "DEVICE=", ""))
USE
*-- Now print to 2nd Printer
SET PRINTER TO NAME "&lcPrinter2."
SELECT (lnSelect)
REPORT FORM printers TO PRINTER NOCONSOLE && Send the report to the
** other printer using the printer attributes
** specified in the Expr memo field.
*-- *****************************
*-- Reset to Default Printer
*-- (assumed to be first printer)
SET PRINTER TO "&lcPrinter1."
RETURN
*-- ****************************************
*-- Set the number of copies into expr field
*-- ****************************************
PROCEDURE l_setCopies
PARAMETERS tnCopies
LOCAL lcCopies, lnx
lcCopies = ALLTRIM(STR(tnCopies))
FOR lnx = 1 TO MEMLINES(expr)
IF "COPIES="$MLINE(expr, lnx)
lcLine = MLINE(expr, lnx)
lcLin2 = LEFT(lcline, AT("=", lcline)) + lcCopies
REPLACE expr WITH STRTRAN(expr, lcLine, lcLin2)
RETURN
ENDIF
ENDFOR
RETURN
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
** All postings, unless explicitly stated otherwise, are the opinions of the
author, and do not constitute legal or medical advice. This statement is added
to the messages for those lawyers who are too stupid to see the obvious.