Search code examples
printingvisual-foxprofoxpro

How to get printer where report was printed


If PROMPT calsue is used in report

REPORT FORM xxx to PRINT PROMPT

User can select printer where report is printed. How to get this printer name for logging?

https://support.microsoft.com/en-us/help/162798/how-to-use-the-set-printer-to-name-command-to-print-to-a-specified-printer-in-visual-foxpro

Show hot to use GetPrinter() for this. This requires removing PROMPT clause from REPORT

How to get printer where report was printed using PROMPT clause: REPORT FORM xxx TO PRINT PROMPT

If this possbible, maybe thereis some sys() function or somethis other or is it possible to get printer name during report print ?

Or should this command re-factored not to use PROMPT clause like:

cPrinter = getprinter()
set printer to name (cPrinter)
REPORT FORM xxx TO PRINT
insert into logfile (PrinterUsedForPrinting) values (cPrinter)

Solution

  • I would suggest using your solution of calling GETPRINTER prior to running the report (without the PROMPT clause). In my long experience using FoxPro/VFP I don't think I've come across a way to determine the printer via REPORT FORM...PROMPT.

    Here's an example wrapper function that you may find useful. I typically call "PickPrinter" prior to running a report. If PickPrinter returns an empty string, I abort the report run.

    FUNCTION PickPrinter
        IF APRINTERS(a_printers) < 1
            MESSAGEBOX("No printers defined.")
            RETURN ""
        ELSE
            lcPrnChoice = ""
            lcPrnChoice = GETPRINTER()
            IF EMPTY(lcPrnChoice)
                RETURN ""
            ELSE
                *** Include quotes around the printer name
                *** in case there are spaces in the name
                lcPrnChoice = "NAME [" + lcPrnChoice + "]"
                SET PRINTER TO &lcPrnChoice
    
                RETURN lcPrnChoice
            ENDIF
        ENDIF
    ENDFUNC