#1
|
|||
|
|||
MERGE with IF field
HI All,
I am trying to trying to use the mail merge utility to generate some inspection reports. Some of the inspection reports will have photos of defects (stored in PhotoPath1), but not all will have them. So I am attempting to use the IF field to check if the Photo Path is a blank (<> ""), and then to paste the picture at the path if there is a path to a defect photo. I can get the photo title to show up only when the Photo Path is not blank, but I am not getting the picture to come in also. I couldn't get the field text to paste in here so I have re-typed it. This is just as it appears in the WORD document. { IF {{MERGEFIELD PhotoPath1} <> "" {INCLUDEPICTURE {MERGEFIELD PhotoPath1} }}\* MERGEFORMAT} I'm hoping that someone has tried this before and can help me navigate through this. Many thanks for your consideration. |
#2
|
||||
|
||||
You need to employ the correct syntax to merge images or you will get no images or the wrong images.
See http://www.gmayor.com/mail_merge_graphics_addin.htm which shows the correct syntax and provides a means of inserting it simply. Your construction also has an unwanted set of brackets, and the mergeformat switch is superfluous. Note that if your merge is pulling the data path from the data source, then that path must have the required double slashes for the path separators. For copying field structures to text forums (and back to fields) you might find http://www.gmayor.com/export_field.htm useful.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
Excellent, thank you! I am testing this merge before I roll it out to my inspection reports, and I created a spreadsheet with two records as the merge source, one with a photo path and one where the photo path is blank. This approach worked with the record that had a valid photo path but produced an error message for the second path (which was blank). Is there an additional result to the Boolean evaluation that needs to be provided if the IF TRUE statement is false (i.e., no path exists)?
|
#4
|
||||
|
||||
You can add "" if you like but it shouldn't really be necessary.
{ IF {Mergefield Condition } <> "" "Do This" "Else Do This" }
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#5
|
|||
|
|||
Thanks! I just found your webpage with this exact problem spelled out. I just saved a Blank.jpg and will try that route. I figure that will accomplish what I'm trying to do and remove the error message at the same time. Thanks so much for your assistance.
|
#6
|
|||
|
|||
Tripped up by syntax again. I used the approach from your webpage to produce the following statement.
{INCLUDEPICTURE {IF {MERGEFIELD PhotoPath1} <> "" {MERGEFIELD PhotoPath1} "Q:\\.....\\Blank.jpg"}} When I merge the test file, the first record merges fine and the picture displays perfectly. For the second record, this syntax gives me an error message (filename not specified). When I hit Alt-F9 to display the field in the merged document, it shows the path on the Q: drive without any quotation marks. If I add an extra set of quotation marks for the Blank.jpg file path, then it returns a blank file path and I still get the error message. Any ideas where I went astray? Thanks. |
#7
|
||||
|
||||
You didn't find that construction on my web site. What you may have found is
{INCLUDEPICTURE {IF TRUE "{Mergefield Path}{Mergefield Image}.jpg"} \d } or in your case {INCLUDEPICTURE {IF TRUE "{Mergefield PhotoPath}Blank.jpg"} \d } This requires that the image is present at the path set in {Mergefield PhotoPath}. To add the conditional field, that must go outside the construction thus { IF {Mergefield PhotoPath} <> "" "{INCLUDEPICTURE {IF TRUE "{Mergefield PhotoPath}Blank.jpg"} \d }" "" } Mergefield Photopath must return "Q:\\Path\\" without the filename See also http://www.gmayor.com/mail_merge_graphics_addin.htm
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#8
|
|||
|
|||
Still getting the "Filename not specified" error. To clarify, the field PhotoPath1 includes the path and the target, perhaps I didn't explain that clearly. From that, my current syntax is:
{IF {MERGEFIELD PhotoPath1} <> "" "{INCLUDEPICTURE {IF TRUE {MERGEFIELD PhotoPath1}}}" ""} Developing flat-head syndrome here. Anything jump out at you from this construction? |
#9
|
||||
|
||||
What does {MERGEFIELD PhotoPath1} alone produce?
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#10
|
|||
|
|||
The field PhotoPath1 comes from a query that pulls the actual file path, adds the quotation marks and replaces the slash with a double slash. So {MERGFIELD PhotoPath1} produces:
"Q:\\RVA\\00-Structures\\Henrico 2015 Traffic Pole Inspxn\\Inspection Photos\\2015_1105_Base Inspections (Utz and Mercogliano)\\PB050025.JPG" |
#11
|
|||
|
|||
OK, I seem to have found a workaround that posts the blank jpg and eliminates the error message. I went into the merge source file and added the Blank.jpg file path as a merge field. It seems a little clumsy since every file will have it, but entering the path into the conditional field produced the "Filename not specified" error. Here's the syntax that finally worked:
{INCLUDEPICTURE {IF {MERGEFIELD PhotoPath1} <> "" {MERGEFIELD PhotoPath1} {MERGEFIELD PhotoBlank}}} For whatever reason, if I don't use the PhotoBlank merge field and instead enter "Q:\\........\\Blank.jpg", I get the error message. When I hit Alt-F9 to show the fields, WORD has removed the quotation marks around the file path and thus the error. If you have a more elegant solution, I am more than willing to entertain it but I can work with this, I think. Your patience and willingness to help is greatly appreciated. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Merge Field Not Populating | JennEx | Mail Merge | 8 | 03-31-2016 06:30 PM |
Mail merge how to link mail merge field value to a column heading | dsummers | Mail Merge | 1 | 05-08-2014 02:59 PM |
Date field inserting merge date in blank field | Lesley | Mail Merge | 5 | 09-30-2013 01:49 AM |
How to ignore a mail merge field if the field is blank | redzan | Mail Merge | 1 | 05-16-2013 08:34 AM |
Merge field source data field | kckay | Mail Merge | 4 | 03-25-2013 11:06 AM |