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!

Preview report if no printer is attached

Status
Not open for further replies.

sdocker

IS-IT--Management
Aug 12, 2010
218
GB
I am trying to preview a report on a laptop that does not have a printer attached, or access to a network printer.

It fails with error no 1298; "Detai1 band is too large for the page."

If I attach a printer it works fine.

Aprinters lists installed printers even if no longer attached, so I don't think it can be much help.

Is there a way to determine if there is a printer attached?

Alternatively, is there a way to trap the error gracefully, despite the fact that the description is not accurate? Someone can end up looking for a fault in a report, when the probem is the lack of a printer.

Thanks,
sam
 
Hi Sam,

Yes, there is a way of checking if a printer is attached. The Windows EnumPrinters() function can be used to enumerate all the attached printers, including network printers and print servers. See for the calling sequence.

However, I wonder if this is what you want. VFP has no way of knowing if there is no printer physically attached to the computer. It's the Windows print spooling system that handles that situation. I'd be surprised if the error you see happens because there is no physical printer attached.

If there is no printer driver installed, that's another matter. In that case, VFP will not be able to generate a preview, because it doesn't know anything about the font metrics or paper sizes used by the target printer. But you say that APRINTERS() does return a list of printers, so you must have at least one driver installed.

Perhaps the best thing you can do is to error-trap your REPORT FORM command, using a TRY / CATCH / ENDTRY structure. Check for Error 1298, and issue an informative message that explains the situation and advises the user to check that the printer is connected.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike,

You're right.

The app lets the user select a default printer for the app, and the error happens if there is no printer selected. There are several printers installed, though not attached, and like you mentioned the driver is there.

So, what I really need is a way to check if a printer has been selected.

I think the TRY / CATCH / ENDTRY will do the trick.

Thanks.
Sam
 
Sam,

I'm not sure about this, but you might also try checking for Error 125 (Printer not ready). However, that might be a relic from FoxPro for DOS, which is retained for compatibility only - although the Help doesn't say that.

Just something to keep in mind.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
The app lets the user select a default printer for the app, and the error happens if there is no printer selected. There are several printers installed, though not attached, and like you mentioned the driver is there.

So, what I really need is a way to check if a printer has been selected.


Are they really changing the workstation's Default Printer?

If not, then a printer is (by Default) already selected by Windows as long as one or more are installed.

An approach you could make would be to make your own VFP Form to display the installed printers (using APRINTERS()) and allow the user to select which one. By doing this YOU would be in control.
* So if they Selected one, your Form would make it the VFP Printer to use for output.
* And if they did not Select one, then the VFP Printer would remain unchanged and use the Windows Default printer.

Good Luck,
JRB-Bldr

 

JRB-Bldr,

The app does what you suggested.
What I'll do now is trap the error and prompt to select a printer.

The problem arose because the printers returned by aPrinter() are network printers, and if the user is not connected to the network, the drivers are not available.

Thank for the ideas. I always learn something.

Sam
 
If the goal is simply to preview the report, may be you can have an 'Option Button' and let the user select Preview/Print. May be set it defalut to Preview. And in your .Click() code, based on the Selection,

1. report form Report_Name noconsole to printer prompt
2. report form Report_Name preview

Nasib



 
I can contribute I recently did a report on a virtual machine having no printers, and the preview works. That's only half the truth, as an XPS driver is there, most Windows versions do have such a initial printer driver installed, so a preview always works.

Bye, Olaf.
 
Yes, but if there is no driver at all intalled (for a physical printer or XPS, PDF or similar), I'd bet that VFP wouldn't be able to do the preview. (Unfortunately, I've no way of testing that.)

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
That's exactly right, Mike, and it used to be a FAQ before Windows shipped with a default (XPS) printer. :) We'd see people complaining about "printer not ready" errors when the actual error was "no printer installed".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top