[Solved] Mail Merge conditions

Discuss the word processor
Post Reply
qu4rk
Posts: 27
Joined: Mon Mar 17, 2014 7:43 pm

[Solved] Mail Merge conditions

Post 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.
Last edited by qu4rk on Wed Mar 19, 2014 6:29 pm, edited 1 time in total.
OpenOffice 4.0.2.2 on Linux
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Mail Merge conditions

Post 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.
AOO4/LO5 • Linux • Fedora 23
User avatar
Villeroy
Volunteer
Posts: 31345
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Mail Merge conditions

Post 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
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
qu4rk
Posts: 27
Joined: Mon Mar 17, 2014 7:43 pm

Re: Mail Merge conditions

Post 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?
OpenOffice 4.0.2.2 on Linux
User avatar
Villeroy
Volunteer
Posts: 31345
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Mail Merge conditions

Post 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
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
qu4rk
Posts: 27
Joined: Mon Mar 17, 2014 7:43 pm

Re: Mail Merge conditions

Post 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!
OpenOffice 4.0.2.2 on Linux
Post Reply