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

Report - selecting the printer programmaticly.

Status
Not open for further replies.

bs6600

Programmer
Sep 23, 2005
56
GB
I want to make a copy of a report, changing the printer. (I need to use a printer with A3 and Courier New,8 to print to a text file with sufficient width).

No matter what I do it stays locked to the default printer.

Any suggestions please

I could change the printer when creating my report or when printing.

When I create my new report I 'use' the existing report then
copy to MyReport.frx
use MyReport;
repl expr, tag and tag2 with ""
repl expr with all the values I want.
repl fontface and fontsize
modi repo myreport &&allows installer to tune the report.

But Page Setup still shows the Windows default printer.

I wondered about SET PRINTER TO NAME ...- but how can I find the server name?. (This is in a utility which could be used anywhere, so I don't want anything interactive.) I'd have the same problem when setting it back to whatever it started with.

Do I need to 'compile' the report to replace tag/tag2?

Sorry that's so long winded.



Bill Spence,
Dunfermline, Scotland
 
Bill,

Sounds like you're basically on the right track.

You're right that you should be using SET PRINTER TO NAME. The normal approach is to use it in conjunction with GETPRINTER(), but that won't work here because you don't want any user involvement.

You can use APRINTERS() to get a list of all installed printers, including those on the network. But that won't tell you which printer is capable of printing A3. You will either have to hard-code the name of the printer, or store it with your configuration data (for an example, in an INI file or a "settings" table).

Then use SET PRINTER TO NAME to switch to that printer. Do that just before you print the report. If you want to switch back to the previous printer afterwards, use SET("PRINTER") to store the name of the previous default printer (before you do the SET PRINTER TO NAME).

Hope this makes sense.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike,

As ever your explanation makes admirable sense.

I'm working on my lap top with no network printer attached so when I looked at aprinters() I didn't see a server name. I know the required printer name so I can find the entry in aprinters(). I'll assume from what you say that the server name will appear - unless I hear from you!

Thanks

Bill Spence,
Dunfermline, Scotland
 
Mike,

I spoke too soon.

I tried this:-

=aprinters(ax,1)
ix=ax[1,1]
set printer to name &ix

but get an error "Error accessing print spooler"

I tried ix="\"+ax[1,1] but no joy

Bill Spence,
Dunfermline, Scotland
 
Bill,

I think this is just a question of syntax.

Instead of this:

Code:
set printer to name &ix

Try this:

Code:
set printer to name (ix)

It's probably the spaces in the printer name that causes the macro expansion to fail.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike

thanks but no - had already tried that!

But this worked:

iy="SET PRINTER TO NAME +'"+ix[1,1]+"'"
? iy

and then
? set("PRINTER"),3) && returns the new name.

Perhaps a blank response from set("PRINTER",3) means the default.

For the record:
? set("PRINTER",3) &&returns blank initailly
set printer to default
? set("PRINTER",3) &&returns the default printer name

Bill Spence,
Dunfermline, Scotland
 
Bill,

I must admit I don't really understand why that worked, but if you've solved the problem, that's what matters.

By the way, if you're using VFP 9.0, you don't need the palava of replacing Expr1 etc. with "". You just untick the Printer Environment option in the Report menu in the report designer (sorry, I expect you already knew that).

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top