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

automation - printer dialog

Status
Not open for further replies.

MgtHargreaves

Programmer
May 12, 2006
33
GB
thread184-1384177

Using the following code :
Code:
#DEFINE wdDialogFilePrintSetup 97
oWord = CreateObject("Word.Application")
oWord.Documents.Add("C:/xxxx/yyy.dot")
WITH oWord.Dialogs(wdDialogFilePrintSetup)
    .Printer=GETPRINTER()
    .DoNotSetAsSysDefault = .t.
    .execute()
ENDWITH
oWord.printout(0)
oWord.ActiveDocument.Close(0)

is it possible to detect whether the user has clicked on 'Cancel' in the printer dialog box ?

Margaret
 
Hello Margaret,

Since you are using the native Visual FoxPro printer dialogue - the one that is invoked by GETPRINTER() - you just need to test the returned value. If it's an empty string, it means the user cancelled.

So, you would do something like this:

Code:
lcPrinter = GETPRINTER()
IF NOT EMPTY(lcPrinter)
  .Printer = lcPrinter
 ... 
  etc.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Hi Mike

I tried that, but oWord.Dialogs(97).Printer always returns the default printer. Even if I set it to "" first

Margaret
 
Sorry, Margaret, but I'm not with you.

As I understand it, you are trying to use the VFP printer dialogue to let the user choose a printer, and then you want to pass the selected printer's name to Word, without displaying Word's own printer dialogue. Have I got that right?

If so, and if the user then cancels out of the VFP dialogue, surely you need to come right out of your printing routine. In other words, you wouldn't set oWord.Dialogs(97).Printer to anything, and you wouldn't do the printout.

Or am I being dense?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Hi Mike

No, surely
Code:
 oWord.Dialogs(97).Printer = GETPRINTER()
is using the Word printer dialog box.

The code I am using was suggested in a previous thread to stop the windows default printer being changed.

The reason for needing to know whether the user has clicked on Cancel, is that the Word document is built up from VFP but is not visible ( this is to produce invoices etc). IF they click on cancel we want to do something else.

Margaret
 
Mike's right. When VFP code like yours issues GetPrinter(), that's calling the VFP function GetPrinter(). If you want to use a Word printer dialog, you have to automate that dialog.

To see the difference, in VFP, issue GetPrinter() in the Command Window. Then, in Word, choose File | Print and see the difference.

Tamar
 
Margaret,

The fact that you are calling the dialogue's Execute method means that the dialogue (that is, Word's printer dialogue) will not be visible.

To quote from the VBA Help file:

Use the Execute method to execute the settings in a dialog box without displaying the dialog box

What you are seeing is the Foxpro dialogue.

The code snippet I posted above will let you take action on a user cancel.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top