Celtic Coding Solutions Blog

Celtic Coding Solutions Blog - for everything computer related

Visual FoxPro - Fix for Error accessing printer spooler (Error: 1957)

Had the following error appear on a Visual FoxPro Application running under Citrix:-

Error Number: 1957

Error message: Error accessing printer spooler.

I found out that this error was caused because sometimes FoxPro cannot determine the default printer.  So a work around was to use the winspool.drv and force FoxPro to the Default Printer name.

Example code as follows (I am defaulting to Win2PDF if no printer is found as this is installed on all our Citrix clients):-

 

PUBLIC cDefaultPrinter

UseStdPrintDefault()

SET PRINTER TO NAME (cDefaultPrinter)

REPORT FORM "TestReport.frx" abortion with a pill TO PRINTER PROMPT NOCONSOLE

 

PROCEDURE UseStdPrintDefault

DECLARE INTEGER GetDefaultPrinter IN winspool.drv;

   STRING  @ pszBuffer,;

   INTEGER @ pcchBuffer

 

abortion effects &&Return default printer name

nBufsize = 250

cPrinter = REPLICATE(Chr(0), nBufsize)

 

= GetDefaultPrinter(@cPrinter, @nBufsize)

cDefaultPrinter = SUBSTR(cPrinter, 1, AT(Chr(0),cPrinter)-1)

lnPrinterCount = APRINTERS(oPrinters)

FOR lnPCount = 1 TO lnPrinterCount

IF oPrinters[lnPCount,1] = 'Win2PDF'

SET PRINTER TO NAME "Win2PDF"

ENDIF

ENDFOR

RETURN

ENDPROC 

Comments are closed