Page 1 of 1

[Solved] Mail Merge conditions

Posted: Tue Mar 18, 2014 6:58 pm
by qu4rk
I have a mail merge. Some of the people are doctors & instead of saying:
Dear John,
I'd like to say:
Dear Dr. Smith,
How do I get those conditions within the mail merge?

FYI, if they are not a doctor, the "prefix" field in my spreadsheet is blank.

Re: Mail Merge conditions

Posted: Tue Mar 18, 2014 8:09 pm
by acknak
I'd have to play with it a bit to be sure, but I think you can use a hidden paragraph field with a condition that checks the db flelds.

Insert > Fields > Other > Functions ...

Alternatively, and I prefer this approach if possible, define a query that does the necessary processing to get a "salutation" field for each record. Then you can display that in the merge document just like any other db field. My SQL skills aren't adequate to say for sure whether that's possible in this case.

Re: Mail Merge conditions

Posted: Tue Mar 18, 2014 8:41 pm
by Villeroy
You can do this with simple spreadsheet formulas.
If it were a real database, you could do it in the database program.
You can do at the end of the pipe in Writer:
Insert>Fields>Other...
Tab [Functions]
Field Type: Conditional Text
Condition: DatabaseName.TableName.PrefixField=="" (yes, 2 equal signs, 2 double-quotes)
Then: DatabaseName.TableName.ForenameField
Else: DatabaseName.TableName.PrefixField" "DatabaseName.TableName.SurnameField

Re: Mail Merge conditions

Posted: Wed Mar 19, 2014 1:44 am
by qu4rk
Villeroy wrote:You can do this with simple spreadsheet formulas.
If it were a real database, you could do it in the database program.
You can do at the end of the pipe in Writer:
Insert>Fields>Other...
Tab [Functions]
Field Type: Conditional Text
Condition: DatabaseName.TableName.PrefixField=="" (yes, 2 equal signs, 2 double-quotes)
Then: DatabaseName.TableName.ForenameField
Else: DatabaseName.TableName.PrefixField" "DatabaseName.TableName.SurnameField
Ok, I did all that. And it seems that the Condition & Then work great. However, when it comes to the Else statement, it prints literally:
DatabaseName.TableName.PrefixField" "DatabaseName.TableName.SurnameField
Of course I substituted my DBname, Tablename & fields. It prints the first names prefectly fine, but then it has that literal statement for whenever there is something in the "prefix" field.

It does the same thing when I delete the space between the quotes. It also just puts their last name when I simply put:
DatabaseName.TableName.SurnameField
Is there something wrong with the syntax of this statement?

Re: Mail Merge conditions

Posted: Wed Mar 19, 2014 1:00 pm
by Villeroy
I'm not sure about all aspects of the syntax.

Condition: DatabaseName.TableName.PrefixField==""
Then: DatabaseName.TableName.ForenameField
Else: DatabaseName.TableName.PrefixField DatabaseName.TableName.SurnameField (space without the double-quotes)

Trying 2 conditional fields:
Condition: DatabaseName.TableName.PrefixField==""
Then: DatabaseName.TableName.ForenameField
Else: DatabaseName.TableName.PrefixField

Condition: DatabaseName.TableName.PrefixField==""
Then: "" (or nothing at all?)
Else: DatabaseName.TableName.SurnameField

Re: Mail Merge conditions

Posted: Wed Mar 19, 2014 6:28 pm
by qu4rk
Villeroy wrote:Trying 2 conditional fields:
Condition: DatabaseName.TableName.PrefixField==""
Then: DatabaseName.TableName.ForenameField
Else: DatabaseName.TableName.PrefixField

Condition: DatabaseName.TableName.PrefixField==""
Then: (leave blank)
Else: DatabaseName.TableName.SurnameField
This works perfectly. I have to put the 2 conditional fields side by side with a space in between. Thanks so much!