Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Word - Automatically merge data and show merged result
Message
From
20/06/2003 09:25:23
 
 
To
20/06/2003 03:59:09
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00801933
Message ID:
00802169
Views:
31
>I have some forms created in word. I link the word documents to a datasource on the local drive to fill in fields on the document. I am trying to make this user-friendly. I initiate the run command to pull up the chosen document, the problem is when the document comes up, it pulls up the document itself with the merge toolbar and the user has to push the merge button to pull up the document merged to the datasource to print, they then have to close the merged document followed by the document itself.
>
>Is there any way to send a command to merge the datasource and pull up only the merged document to be printed making the app more user-friendly?
>
>Thanks,
>
>
>Kev

Warning: Untested code (for llToPrinter = .T.)

#Define MYDBC _samples+"\DATA\testdata.DBC"
#Define wdSendToEmail 2
#Define wdSendToFax 3
#Define wdSendToNewDocument 0
#Define wdSendToPrinter 1
#DEFINE wdDoNotSaveChanges 0
#DEFINE wdSaveChanges -1

cSQLStatement1 = "SELECT * FROM employee where title like [Sales%]"
cSQLStatement2 = ""

* Be carefull with where clause - where title = [Sales] fails
* for ODBC uses ANSI SQL (exact match)
* Two strings for first is limited to 255 chars
Local llToPrinter
oWordDocument=Createobject("word.application") && Create word object
With oWordDocument
.Documents.Add(Sys(5)+Curdir()+'mytemplate.dot') && Use a predefined template
With .ActiveDocument.MailMerge
.OpenDataSource(,,,.T.,,,,,,,, ;
"DSN=Visual FoxPro Database;SourceDB="+MYDBC+;
";SourceType=DBC;Exclusive=No;",;
cSQLStatement1, cSQLStatement2) && Open data source - Link to source
If llToPrinter
.Application.Options.PrintBackGround = .T.
.Destination = wdSendToPrinter
Else
.Destination = wdSendToNewDocument
Endif
.Execute
Endwith
.Visible = !llToPrinter
Endwith
If llToPrinter
oWatcher = CreateObject('myTimer')
Read events
endif

Define Class myTimer As Timer
Procedure Timer
With oWordDocument
If .BackgroundPrintingStatus > 0 && Wait printing to finish
Return
Endif
For Each oDoc In .Documents
oDoc.Close(wdDoNotSaveChanges)
Endfor
oDoc = .Null.
.Quit(wdDoNotSaveChanges)
EndWith
this.Enabled = .F.
Clear Events
Endproc
Enddefine
Cetin
Çetin Basöz
MS Foxpro MVP, MCP
Welcome to FoxyClasses
Türkçe bir Foxpro sitesi Fox4um

RE:

This looks good, but I am trying to quickly piece out only the part I want. It looks like this creates the new doc, links the source, prints, etc. As stated before, the document (form) is already in a destination that VFP will know as predetermined, and the source is already linked to it, and I am using the run command to pull the document up with word and the link is automatic. I simply want to send the command to perform the merge (simulate the user pressing the merge button on the toolbar in word). I may be able to piece this step out of what you sent me, but if you could send me a limited version doing just what I want to in the meantime, that would be geat.

Thanks
``` Appreciate a normal day, it is always better than a bad one ```

Kev
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform