Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
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 | |
|
|
![]() |
||||
Thread | Forum | |||
Missing date field in file select field (get data source) | Mailmerge | |||
database field - merge single field from excel list | Microsoft Word Help | |||
How can I maintain a database used as a source for mail functions | Microsoft Word Help | |||
How can I maintain a database used as a source for mail functions | Mailmerge | |||
how do I add a field to the data source file address list once I . | Mailmerge |