Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Word Merge Help...
Message
From
29/01/2008 08:45:41
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
28/01/2008 15:10:41
Chris Sund
Silhouette Solutions
Utah, United States
General information
Forum:
Visual FoxPro
Category:
Reports & Report designer
Miscellaneous
Thread ID:
01286305
Message ID:
01286561
Views:
44
This message has been marked as the solution to the initial question of the thread.
Another sample using VFPOLEDB.
Wait Window Nowait "Creating Word Document.Please wait..."
* Word constants header file
#include "wdconst.h"
#Define NL Chr(13)+Chr(10)
m.lcConnection = "Provider=VFPOLEDB;Data Source="+_samples+'data\testdata.dbc'
TEXT TO m.lcUDL TEXTMERGE noshow
[oledb]
<<m.lcConnection>>
ENDTEXT
m.lcSource = Forcepath(Sys(2015)+'.udl',Sys(2023))
Strtofile(m.lcUDL,m.lcSource)
lcSQLStatement = "select first_name,last_name,title,hire_date,notes from employee"
*** set the LOCALEID to English
nlLocaleId=Sys(3004)  && Save local id
=Sys(3006,1033)    && We will be sending instructions in English
*** set the LOCALEID to English

oWordDocument=Createobject("word.application") && Create word object
With oWordDocument
  .documents.Add
  With .ActiveDocument.Mailmerge
    .OpenDataSource(m.lcSource, wdOpenFormatAuto,,,.T.,,,,,,,m.lcConnection, m.lcSQLStatement)
    .EditMainDocument	&& Activate the main document

    * Write mailmerge as if not using a template
    .Application.Selection.TypeText("Dear,"+Chr(13))
    With .Application.Selection.Font
      .Name = 'Times New Roman'
      .Italic = .T.
      .Size = 14
    Endwith
    .Fields.Add(.Application.Selection.Range, 'First_Name')
    .Application.Selection.TypeText(',')
    .Fields.Add(.Application.Selection.Range, 'Last_Name')
    With .Application.Selection.Font
      .Name = 'Times New Roman'
      .Italic = .F.
      .Size = 10
    Endwith
    .Application.Selection.TypeText(NL+NL+;
      'Please update your info and send back. Current notes are as follows:'+;
      NL+NL)
    With .Application.Selection.Font
      .Name = 'Arial'
      .Size = 12
      .Color = Rgb(0,0,255)
    Endwith
    .Fields.Add(.Application.Selection.Range, 'Notes')
    * Write mailmerge as if not using a template

    * Send to a new doc - to check what we get
    .Destination = wdSendToNewDocument
    .Execute
  Endwith
  .Visible = .T.   && Show word app
  .Activate
Endwith
Wait Clear
Erase (m.lcSource)
**** Set the LocaleId to the previous value
=Sys(3006,Val(nlLocaleId))
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