Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / February 2007

Tip: Looking for answers? Try searching our database.

Check if file exists

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
FUBARinSFO - 23 Feb 2007 03:46 GMT
Hi --

I want to pull an image from an image file (.jpg) into my document
(table cell) if the image file exists, otherwise I want to leave the
table cell blank.  I've searched this group, and there doesn't seem to
be any way to do this with just mail merge functions.

I can of course preprocess my data source and file directory with VBA,
output a processed file with fields indicating the image file to pull
in (or not), and then use that processed file as my data source, but
I'm trying to do this directly in mail merge.

Any help or pointers would be appreciated.

-- Roy Zider

Word 2003, Windows XP SP2
Peter Jamieson - 23 Feb 2007 09:48 GMT
I don't think there is a way to do this using fields, at least not without
writing your own text converter, which I cannot recommend.

To do it, you would have to construct a field that returns a testably
different result depending on whether or not the file exists, e.g.

{ INCLUDEPICTURE "{ IF "{ SOMEFIELDTYPE "<picturepath>" }" = "Error! File
not found" "<blankpicturepath>" "<picturepath>" }" }

I don't think you can successfully use INCLUDEPICTURE as the SOMEFIELDTYPE.
In theory you might be able to use

{ INCLUDEPICTURE "{ IF "{ INCLUDETEXT "<picturepath>" \c Recover }" = ""
"<blankpicturepath>" "<picturepath>" }" }

but in practice Word seems to get very confused if you attempt this (it
takes quite a long time to read large image files, for one thing), and does
not reliably evaluate INCLUDETEXT in the way you might hope. Possibly worth
trying for your own satisfaction.

Another approach might be to use a DATABASE field to invoke some SQL that
tests for file existence. However, I don't think you can do this using Jet
SQL because none of the functions you might use for that (dir, filelen,
etc.) are available.

Other ways you can potentially avoid preprocessing (other than
postprocessing!):
a. the official way, using Word's MailMerge events, e.g. in VBA
b. if your data source happens to be an Access .mdb and you can connect
using DDE, write an Access VBA function that tests for file existence and
returns either a flag or perhaps the name of a blank file. Then call that
function in an Access query and use that query as your data source. (NB, as
far as I know, you can't combine this approach with the DATABASE approach
because the DATABASE field cannot get data from an Access query via DDE any
more).

Peter Jamieson

> Hi --
>
[quoted text clipped - 13 lines]
>
> Word 2003, Windows XP SP2
FUBARinSFO - 23 Feb 2007 18:08 GMT
Peter:

I was afraid of that.  I had read your earlier posts and comments
about the use of INCLUDETEXT.  Reading hundreds of jpg files to force
an error message wasn't in the cards. In addition, it seems Microsoft
has dropped the error message from the use if INCLUDEPICTURE
FUBARinSFO - 23 Feb 2007 18:11 GMT
Peter:

I was afraid of that.  I had already read your earlier comments about
INCLUDETEXT, and no way was I going to search through hundreds of jpg
files as a way to force an error message.  Microsoft Word used to emit
an error message (along the lines you mention here) when
INCLUDEPICTURE did not find the requested file, but evidently it now
goes silently into the night.

I will simply preprocess the data source and feed that preprocessed
source into the mail merge document, and be done with it.

Thank you so much for your prompt and comprehensive reply.

-- Roy Zider
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.