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 03:59:09
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
19/06/2003 16:34:26
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00801933
Message ID:
00802105
Views:
32
>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

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform