Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Word Mailmerge from Database
Message
From
20/03/2002 06:40:24
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00634818
Message ID:
00634851
Views:
19
This message has been marked as the solution to the initial question of the thread.
>Hi all,
>
>I'm trying to perform a mailmerge in word but using a table that is part of a database. Is this possible?
>
>I've setup a DSN to the "Microsoft FoxPro VFP Driver" and selected the DBC option but when I select the table as the MailMerge data source I'm getting the error:
>
>ODBC Error: [Microsoft}{ODBC Visual FoxPro Driver]Cannot open file d:\rapid version 3\test.
>Sql State: S1000
>Return Code: SQL_ERROR
>
>where the file listed is the DBC linked to the selected table.
>
>Any assistance would be appreciated.

Caroline,
Below code works for me :
#Define MYDBC _samples+"\DATA\testdata.DBC"
#Define wdSendToEmail  2
#Define wdSendToFax  3
#Define wdSendToNewDocument  0
#Define wdSendToPrinter  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

oWordDocument=createobject("word.application")	&& Create word object
With oWordDocument
  .Documents.Add(sys(5)+curdir()+'mmerge.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
    .Destination = wdSendToNewDocument
    .Execute
  Endwith
  .Visible = .t.
Endwith
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
Reply
Map
View

Click here to load this message in the networking platform