PDA

View Full Version : Windows 10|Word 2010 Mail Merge with Excel data via Visual Foxpro



KevinRHunt
08-18-2016, 07:49 PM
Hi,

I have a Visual FoxPro(VFP) application that has been doing mail merges into Word using the VFP ODBC driver and a VFP table.

After some of my clients have upgraded to Windows 10 and Word 2010 that merge no longer works. My investigation would appear to indicate that the ODBC driver is no longer recognized by Win 10|Word 2010.

So I thought I'd try to use an Excel file (xls) and use that for the merge.

Everything works except when I run this code


oDocument.MailMerge.OpenDataSource( cResultFile, ; && 01 - Name - Data Source File Name
0, ; && 02 - Format - wdOpenFormat
.F.,; && 03 - ConfirmConversions - Display Convert File Dialog Box
.F.,; && 04 - ReadOnly
,; && 05 - LinkToSource - Perform Query Specified by Connection & SQL Statement Each Time
.F.,; && 06 - AddToRecentFiles - Add File Name to the List of Recently Used Files in File Menu
,; && 07 - PasswordDocument - Password Used to Open the Data Source
,; && 08 - PasswordTemplate - Password used to Open the Template
,; && 09 - Revert - Controls what happens if Name is the file name of an Open Document
,; && 10 - WritePasswordDocument - Password used to save changes to the document
,; && 11 - WritePasswordTemplate - Password used to save changes to the template
,; && 12 - Connection - A Range within which the Query Specified by SQLStatement is to be performed
,; && 13 - SQLStatement - Defines Query options for retrieving data
, ; && 14 - SQLStatement1 - Used if the query string is longer than 255 characters
,; && 15 - OpenExclusive - .T. to open exclusively
) && 16 - SubType -



I get a dialog asking me to select a Table, which is actually the name of the Worksheet in the XLS file and there isn't any other Table or Range in the file.

If I click on OK, the merge goes through as designed.

I've uploaded the message as shown below.

1833

Any help will be greatly appreciated, my clients are not too happy ...

KevinRHunt
08-18-2016, 07:51 PM
The code isn't coming out very cleanly, I've attached an image ...

1834

Admin
08-19-2016, 08:38 AM
Not sure this would work, give it a try.

Convert the range into a table. Select the range > Go to INSERT > Table.
You can rename the table. To do so, select any cell in the table, Go to DESIGN and you can see the table name there. Just rename it.

Use this name in the code.

Again I'm not sure this would work.