Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Help With Word and Merging
Message
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Title:
Help With Word and Merging
Miscellaneous
Thread ID:
00298479
Message ID:
00298479
Views:
35
I am trying to open a word document a merge to a table in VFP 5.a

OK Here is my problem(s)

First When the Document opens its looking for a data source

Second it opens two of the documents

Question

Can I set the Document Word opens to a default so the .Open() command only opens it once?

How can I set the .OpenDataSource() to open before the document opens and then askes for it.

Any Help Would be appreciated.

Thanks Ron

*=============================================
PROCEDURE MergeToWord
*=============================================
* Procedure......: MergeToWord
*
* Parameters.....: pcSQL = SQL from what file to select from
* pcTemplate = The name of the Word document to
* use as the mailmerge document (include path)
* plShow = .t. if you want to display Word, .f.
* otherwise
*
* NOTES: To find information about the Word hierarchy start WORD.
* Select Tools/Macro/Visual Basic Editor.
* Choose Help/Contents and Index - Look under
* "Microsoft Word Visual Basic Reference"
*==================================================================================================================
LPARAMETERS pcSQL, pcTemplate, plShow

LOCAL lnDestination, lcOldError

* Save the Old error routine
lcOldError = ON("ERROR")

* Check parameters
WAIT WINDOW NOWAIT "Creating Word Document..." && Inform user

* Start Word and make it visible
loWordApp = CREATEOBJECT("Word.Application")

* Destination
IF plShow
lnDestination = 0 && 0 = New Document
ELSE
lnDestination = 1 && 1 = To Printer
ENDIF

* && Mailmerge Main Document
loWordDoc = loWordApp.Documents.OPEN(pcTemplate)

WITH loWordDoc.MailMerge
* Open the MailMerge data source file
* See NOTES above for information about where to find
* information on the OpenDataSource method
&& Open data source - Link to source
.OpenDataSource(,,,,,,,,,,,"DSN=Calltrack Docs;", pcSQL)
.Destination = lnDestination && Where to send it

* Word specific error handler
ON ERROR DO WordError

.Execute && Run the mailmerge
ENDWITH

IF plShow
loWordApp.VISIBLE = .T.
loWordApp.WindowState = 1
ENDIF

IF !plShow
loWordDoc.CLOSE(.F.) && Close - No Save
WAIT WINDOW "Waiting for word to finish..." TIME 2
loWordApp.QUIT
ENDIF

* Reset error handler
IF !EMPTY(lcOldError)
ON ERROR &lcOldError
ENDIF

*WAIT WINDOW "Waiting for word to finish..." TIME 2
RELEASE loWordApp
Ronald L. Thorp
http://www.Fox-Pros.com
Fox-Pros, Inc.
Office 407-498-0100
Reply
Map
View

Click here to load this message in the networking platform