Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
[email protected] martin.craig1@googlemail.com is offline
external usenet poster
 
Posts: 3
Default CSV file as source for DATABASE field

I'm trying to use a CSV file and a DATABASE field to programatically
insert a table into a mail merge document. In the document I've put
something like:

{ DATABASE \d "{ MERGEFIELD table_csv_file }" \l "2" \b "47" \*
MERGEFORMAT }

I then write a temporary CSV file, put the filename in the
table_csv_file field in my main CSV file and kick off the mail merge
using the latter as its data source.

It basically works. Unfortunately when the template document is first
loaded I get the error:

"This data source cannot be opened because it is not supported by the
application"

If I click 'OK', it carries on and merges correctly, including the
table. It seems to be complaining because before the merge takes place
the field is unset and therefore doesn't point to a valid data source.
Any ideas how I can suppress this error or get around it some other
way?

Many thanks for any help,
Martin.
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default CSV file as source for DATABASE field

I tried this, but with simple tests have not been able to reproduce the
problem (using Word Word 2007).

Which version of Word & Windows?

Where are your data files located? (e.g. are they on a local drive or a
network drive?)

Are they actually .csv files with comma-delimited values, or do they
have different extensions and/or a different delimiter.

If you double-click on your .csv files in My CDOmputer/Windows Explorer,
do they open in Excel?

Peter Jamieson

http://tips.pjmsn.me.uk
Visit Londinium at http://www.ralphwatson.tv

On 19/10/2009 14:40, wrote:
I'm trying to use a CSV file and a DATABASE field to programatically
insert a table into a mail merge document. In the document I've put
something like:

{ DATABASE \d "{ MERGEFIELD table_csv_file }" \l "2" \b "47" \*
MERGEFORMAT }

I then write a temporary CSV file, put the filename in the
table_csv_file field in my main CSV file and kick off the mail merge
using the latter as its data source.

It basically works. Unfortunately when the template document is first
loaded I get the error:

"This data source cannot be opened because it is not supported by the
application"

If I click 'OK', it carries on and merges correctly, including the
table. It seems to be complaining because before the merge takes place
the field is unset and therefore doesn't point to a valid data source.
Any ideas how I can suppress this error or get around it some other
way?

Many thanks for any help,
Martin.

  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
[email protected] martin.craig1@googlemail.com is offline
external usenet poster
 
Posts: 3
Default CSV file as source for DATABASE field

Hi, thanks for looking at this.

On 19 Oct, 17:40, Peter Jamieson
wrote:
I tried this, but with simple tests have not been able to reproduce the
problem (using Word Word 2007).

Which version of Word & Windows?


Windows XP and Word 2007

Where are your data files located? (e.g. are they on a local drive or a
network drive?)


They're on a network drive


Are they actually .csv files with comma-delimited values, or do they
have different extensions and/or a different delimiter.


They are comma-separated files with .CSV extension.


If you double-click on your .csv files in My CDOmputer/Windows Explorer,
do they open in Excel?


They don't open in Excel by default because I've associated .CSV files
with a text editor. However if I select Open With-Excel they do open.

Initially I was writing the .csv files in UTF16, however Excel does
not appear to recognize this (the headers and rows all appear in a
single cell) so I've gone back to writing ANSI text which Excel does
open correctly. Unfortunately this doesn't make any difference to the
mail merge error from Word.

The error occurs during the Open call to Word, i.e. before the data
source has been attached. The same error occurs if I open the template
document manually in Word. So I tried attaching a default mail merge
data source to the template document. This means I don't get the error
when I open the template document normally (I get the usual messages
about 'can I run this SQL query'). However again I am still seeing the
error after the Open call in my application!

So still stuck, I'm afraid. Thanks for the suggestions and I'd be
grateful for any other ideas.

Cheers,
Martin


Peter Jamieson

http://tips.pjmsn.me.uk
Visit Londinium athttp://www.ralphwatson.tv

On 19/10/2009 14:40, wrote:

I'm trying to use a CSV file and a DATABASE field to programatically
insert a table into a mail merge document. In the document I've put
something like:


{ DATABASE \d "{ MERGEFIELD table_csv_file }" \l "2" \b "47" \*
MERGEFORMAT }


I then write a temporary CSV file, put the filename in the
table_csv_file field in my main CSV file and kick off the mail merge
using the latter as its data source.


It basically works. Unfortunately when the template document is first
loaded I get the error:


"This data source cannot be opened because it is not supported by the
application"


If I click 'OK', it carries on and merges correctly, including the
table. It seems to be complaining because before the merge takes place
the field is unset and therefore doesn't point to a valid data source.
Any ideas how I can suppress this error or get around it some other
way?


Many thanks for any help,
Martin.


  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default CSV file as source for DATABASE field

OK, I see what you mean now.

I've had a look around, and the following seems to have a chance of working:

{ DATABASE \d "{ IF "{ MERGEFIELD table_csv_file }" = ?table_csv_file?"
"the pathname of a suitable data file that you know exists" "{
MERGEFIELD table_csv_file }" }" " \l "2" \b "47" }

There may well be a neater approach that exploits some other oddity of
the "field language" when the merge main document is not actually
connected to a data source.

What's going on here? Well, I get the impression that when there is no
data source, Word is trying to open a database called something like
"«table_csv_file»" (i.e. the "chevron" display version of { MERGEFIELD
table_csv_file } ). However, those chevrons do not actually appear to be
normal chevrons when it comes to making comparisons. It may be possible
to identify the characters that Word is actually using, but for now it
seems enough to use the wildcard "?" to avoid having to pin that down.

Peter Jamieson

http://tips.pjmsn.me.uk

On 20/10/2009 09:41, wrote:
Hi, thanks for looking at this.

On 19 Oct, 17:40, Peter
wrote:
I tried this, but with simple tests have not been able to reproduce the
problem (using Word Word 2007).

Which version of Word& Windows?


Windows XP and Word 2007

Where are your data files located? (e.g. are they on a local drive or a
network drive?)


They're on a network drive


Are they actually .csv files with comma-delimited values, or do they
have different extensions and/or a different delimiter.


They are comma-separated files with .CSV extension.


If you double-click on your .csv files in My CDOmputer/Windows Explorer,
do they open in Excel?


They don't open in Excel by default because I've associated .CSV files
with a text editor. However if I select Open With-Excel they do open.

Initially I was writing the .csv files in UTF16, however Excel does
not appear to recognize this (the headers and rows all appear in a
single cell) so I've gone back to writing ANSI text which Excel does
open correctly. Unfortunately this doesn't make any difference to the
mail merge error from Word.

The error occurs during the Open call to Word, i.e. before the data
source has been attached. The same error occurs if I open the template
document manually in Word. So I tried attaching a default mail merge
data source to the template document. This means I don't get the error
when I open the template document normally (I get the usual messages
about 'can I run this SQL query'). However again I am still seeing the
error after the Open call in my application!

So still stuck, I'm afraid. Thanks for the suggestions and I'd be
grateful for any other ideas.

Cheers,
Martin


Peter Jamieson

http://tips.pjmsn.me.uk
Visit Londinium athttp://www.ralphwatson.tv

On 19/10/2009 14:40, wrote:

I'm trying to use a CSV file and a DATABASE field to programatically
insert a table into a mail merge document. In the document I've put
something like:


{ DATABASE \d "{ MERGEFIELD table_csv_file }" \l "2" \b "47" \*
MERGEFORMAT }


I then write a temporary CSV file, put the filename in the
table_csv_file field in my main CSV file and kick off the mail merge
using the latter as its data source.


It basically works. Unfortunately when the template document is first
loaded I get the error:


"This data source cannot be opened because it is not supported by the
application"


If I click 'OK', it carries on and merges correctly, including the
table. It seems to be complaining because before the merge takes place
the field is unset and therefore doesn't point to a valid data source.
Any ideas how I can suppress this error or get around it some other
way?


Many thanks for any help,
Martin.


  #5   Report Post  
Posted to microsoft.public.word.mailmerge.fields
[email protected] martin.craig1@googlemail.com is offline
external usenet poster
 
Posts: 3
Default CSV file as source for DATABASE field

Brilliant! That works perfectly, many thanks.

I'd already tried a similar approach but I'd been checking to see if
the mergefield was blank, which failed. I didn't realize that Word
actually set it to the «» text when there isn't a data source
attached.

Cheers,
Martin


On 20 Oct, 19:58, Peter Jamieson
wrote:
OK, I see what you mean now.

I've had a look around, and the following seems to have a chance of working:

{ DATABASE \d "{ IF "{ MERGEFIELD table_csv_file }" = ?table_csv_file?"
"the pathname of a suitable data file that you know exists" "{
MERGEFIELD table_csv_file }" }" " \l "2" \b "47" }

There may well be a neater approach that exploits some other oddity of
the "field language" when the merge main document is not actually
connected to a data source.

What's going on here? Well, I get the impression that when there is no
data source, Word is trying to open a database called something like
"«table_csv_file»" (i.e. the "chevron" display version of { MERGEFIELD
table_csv_file } ). However, those chevrons do not actually appear to be
normal chevrons when it comes to making comparisons. It may be possible
to identify the characters that Word is actually using, but for now it
seems enough to use the wildcard "?" to avoid having to pin that down.

Peter Jamieson

http://tips.pjmsn.me.uk

On 20/10/2009 09:41, wrote:

Hi, thanks for looking at this.


On 19 Oct, 17:40, Peter
wrote:
I tried this, but with simple tests have not been able to reproduce the
problem (using Word Word 2007).


Which version of Word& *Windows?


Windows XP and Word 2007


Where are your data files located? (e.g. are they on a local drive or a
network drive?)


They're on a network drive


Are they actually .csv files with comma-delimited values, or do they
have different extensions and/or a different delimiter.


They are comma-separated files with .CSV extension.


If you double-click on your .csv files in My CDOmputer/Windows Explorer,
do they open in Excel?


They don't open in Excel by default because I've associated .CSV files
with a text editor. However if I select Open With-Excel they do open.


Initially I was writing the .csv files in UTF16, however Excel does
not appear to recognize this (the headers and rows all appear in a
single cell) so I've gone back to writing ANSI text which Excel does
open correctly. Unfortunately this doesn't make any difference to the
mail merge error from Word.


The error occurs during the Open call to Word, i.e. before the data
source has been attached. The same error occurs if I open the template
document manually in Word. So I tried attaching a default mail merge
data source to the template document. This means I don't get the error
when I open the template document normally (I get the usual messages
about 'can I run this SQL query'). However again I am still seeing the
error after the Open call in my application!


So still stuck, I'm afraid. Thanks for the suggestions and I'd be
grateful for any other ideas.


Cheers,
Martin


Peter Jamieson


http://tips.pjmsn.me.uk
Visit Londinium athttp://www.ralphwatson.tv


On 19/10/2009 14:40, wrote:


I'm trying to use a CSV file and a DATABASE field to programatically
insert a table into a mail merge document. In the document I've put
something like:


{ DATABASE \d "{ MERGEFIELD table_csv_file }" \l "2" \b "47" \*
MERGEFORMAT }


I then write a temporary CSV file, put the filename in the
table_csv_file field in my main CSV file and kick off the mail merge
using the latter as its data source.


It basically works. Unfortunately when the template document is first
loaded I get the error:


"This data source cannot be opened because it is not supported by the
application"


If I click 'OK', it carries on and merges correctly, including the
table. It seems to be complaining because before the merge takes place
the field is unset and therefore doesn't point to a valid data source..
Any ideas how I can suppress this error or get around it some other
way?


Many thanks for any help,
Martin.


Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Missing date field in file select field (get data source) Leslie Gottlieb Mailmerge 2 August 24th 09 11:18 PM
database field - merge single field from excel list Big Bad Bev Microsoft Word Help 1 June 7th 08 10:34 PM
How can I maintain a database used as a source for mail functions Beverly907 Microsoft Word Help 5 April 11th 08 02:35 PM
How can I maintain a database used as a source for mail functions Beverly907 Mailmerge 1 April 2nd 08 01:57 AM
how do I add a field to the data source file address list once I . Rod Mailmerge 1 May 16th 07 05:38 PM


All times are GMT +1. The time now is 12:14 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"