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

Selecting printer and tray programaticaly

Status
Not open for further replies.

jesylv

MIS
Jul 1, 2001
135
My application needs to send specific reports to specific printers (easy) and to specific trays (not so easy). Using REPORT FORM myRep TO PRINTER PROMPT is not an option given that 10 to 12 reports are printed in a batch.

I think the solution to this problem probably involves using a Win api function. Any ideas????


Jean
 
Hi Jean,

Have you tried SYS(1037) command just before the report command.. instead of using PROMPT.
:) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
You can check the current printer information with the PRTINFO() Function. The Help file also lists the valid values that are stored in the EXPR field of the first record in the report (.FRX) file. If you keep the report files outside of your .EXE, you can modify the FRX file with the value(s) you require. The "tray" is #7 - DEFAULTSOURCE. For more details, check out - "INFO: Print Setup Options Saved with the Report".

Rick
 
jesylv


and to specific trays (not so easy).

You will have to make a call to the function below to change tray any time you need to do so. It means hacking you report and replace the current value of DEFAULTSOURCE to whatever value you need. And if there is no DEFAULTSOURCE entry it will put one.

Code:
DO CHANGETRAY WITH "C:\myreport.FRX", 1 && OR WHATEVER TRAY YOU WANT

FUNCTION CHANGETRAY
LPARAMETER lcFRX, lnTray
LOCAL lcNewExpr, lnStartCopiesLine, lcStartAtCopiesLine, lnEndCopiesLine ;
    lnLenCopiesLine, lcTop, lcBottom
#DEFINE vfCRLF CHR(13) + CHR(10)

IF !(UPPER(RIGHT(lcFRX, 4)) = ".FRX")
    lcFRX = lcFRX + ".FRX"
ENDIF
USE (lcFRX)
LOCATE FOR objType = 1 AND objCode = 53

IF EMPTY(EXPR)

    lcNewExpr = "DEFAULTSOURCE=" + ALLT(STR(lnTray)) + vfCRLF
ELSE

    lnStartCopiesLine = ATC("DEFAULTSOURCE", EXPR)
    lcStartAtCopiesLine = SUBSTR(EXPR, lnStartCopiesLine)
    lnEndCopiesLine = ATC(vfCRLF, lcStartAtCopiesLine)
    lnLenCopiesLine = LEN(SUBSTR(lcStartAtCopiesLine, 1, lnEndCopiesLine))
    lcTop = SUBSTR(EXPR, 1, lnStartCopiesLine - 1)
    lcBottom = SUBSTR(EXPR, (LEN(lcTop) + lnLenCopiesLine))
    lcNewExpr  = lcTop + "DEFAULTSOURCE=" + ALLT(STR(lnTray)) + lcBottom

ENDIF

REPLACE EXPR WITH lcNewExpr
USE IN (lcFRX)
ENDFUNC
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
jesylv

Disregard my suggestion above. It applies more to change a print tray for the same report .
But I found that for example if I need to print a specific report to a specific tray, if I modify the report on the development box with the appropropriate printer driver loaded, go to page setup and select the right tray and save the report, it should go to the right tray. So if you repeat this for all the reports, it should work. Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
Hi Mike

Thanks for the suggestions.

I would like to stay away from having to modify reports with the appropriate printer driver loaded because it increase maintenance costs and reduces the application portability. I think I am going to explore the possibility of hacking FRX and LBL files at runtime.

Furthermore I dislike the idea of distributing lbx and frx files. Such files tend to disappear or get corrupted.

What if I use a table to keep frx/frt or lbx/lbt information and destination information.

TABLE myReports

RepName C 30
FRX_LBX Memo binary
FRT_LBT Memo Binary
DEVICE C 254
DEFAULTSOURCE I

System admin would specify destination for each reports in this table. When a report is requested, I build a frx/flbx file and then modify its expr content (your code supplied is a good basis) and then execute REPORT FORM or LABEL FORM.

I will test and let you know how it works.....



Jean
 
Jean,
I found it interesting that Mike and I gave you the same answer, from different perspectives at almost the same time. I actually use a variant of Mike's code, and your idea of creating temp "modified" versions of the base Reports and Labels is a good one, and can be the basis of a Report Manager. (You'll just need to save off variants of reports that users migh want to modify.)

The following code will allow you to extract files out of your .EXE, so you can modify them.
Code:
LPARAMETERS p_cFileName, p_cOutPathFile
** cute kludge complements Vlad Grynchyshyn on the UT **
CREATE CURSOR ttt (ttt M)
APPEND BLANK
APPEND MEMO ttt.ttt FROM (p_cFileName)
lcSvSafety = SET("SAFETY")
SET SAFETY OFF
COPY MEMO ttt.ttt to (p_cOutPathFile)
IF lcSvSafety <> &quot;OFF&quot;
   SET SAFETY OFF
ENDIF
USE in ttt
Rick
 
Hi Rick

Thanks for the tip. I didn't realise it was possible to extract ressources from an EXE file. Opens a lot of possibilities. As it relates to the piece of code you suggested may I propose the following:

Code:
LPARAMETERS pcFileName, pcOutPathFile
LOCAL lcSafety, lcFile

lcSafety = SET(&quot;SAFETY&quot;)
SET SAFETY OFF
lcFile = FILETOSTR(pcFilename)
STRTOFILE(lcFile, pcOutPathFile)
SET SAFETY &lcSafety.


Jean
 
Jean,
If your code works, great. This was written for FP 2.x - before the functions you use even existed. There is almost always multiple ways to do the same thing in FoxPro - if it works, use it!

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top