[Solved] Mail merge: Conditionally omit records

Writing a book, Automating Document Production - Discuss your special needs here
Locked
rowan.bradley
Posts: 22
Joined: Sun Jan 29, 2017 3:09 pm

[Solved] Mail merge: Conditionally omit records

Post by rowan.bradley »

I am trying to print some address labels from data in a spreadsheet. I have a column in the spreadsheet called Print which is set to "Yes" if that row is to be printed, and to blank if it is not. There are 14 labels on one sheet, so my mail merge document prints 14 labels, and uses "Next record" to move to the next before each individual label. How do I omit the records that do not have Print set to Yes?

Thank you - Rowan
Last edited by MrProgrammer on Thu Jan 05, 2023 8:09 pm, edited 1 time in total.
Reason: Tagged ✓ [Solved] -- MrProgrammer, forum moderator
OpenOffice 4.1.3 on Windows 8.1 X64
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Mail merge: how to conditionally omit some records

Post by John_Ha »

Sort on the column with "Yes" and print only the first "yes" records.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
rowan.bradley
Posts: 22
Joined: Sun Jan 29, 2017 3:09 pm

Re: Mail merge: how to conditionally omit some records

Post by rowan.bradley »

Is there no "filter" facility like MS Word has? Where you can specify a boolean expression containing field values? I'm sure I have seen this in "how to" pages.

Rowan
OpenOffice 4.1.3 on Windows 8.1 X64
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Mail merge: how to conditionally omit some records

Post by John_Ha »

Not to my knowledge. The User Guide says
In the Mail Merge dialog box (Figure 309), you can choose to print all records or selected records. To select records to be printed, use Ctrl+click to select individual records. To select a block of records, select the first record in the block, scroll to the last record in the block, and Shift+click on the last record.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
Mountaineer
Posts: 318
Joined: Sun Sep 06, 2020 8:27 am

Re: Mail merge: how to conditionally omit some records

Post by Mountaineer »

rowan.bradley wrote: Thu Dec 29, 2022 12:55 am Is there no "filter" facility like MS Word has? Where you can specify a boolean expression containing field values? ...
I've not tried this with a spreadsheet, as my data now resides in databases, but we can query datasources with Base. "Simple" datasources like csv and dBase does not support the full range of options a real sql-Database like sqlite, hsqldb or firebird would give but simple queries are possible.

Word has to do a lot of stuff "alone" as it was sold separate and people had neither Excel, nor Access to help. Aoo/LO have an integrated component to handle data/databases, so does not need to repeat this functions in Writer.
OpenOffice 3.1 on Windows Vista
User avatar
MrProgrammer
Moderator
Posts: 4909
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Mail merge: how to conditionally omit some records

Post by MrProgrammer »

rowan.bradley wrote: Wed Dec 28, 2022 9:13 pm conditionally omit some records
You will specify which records to include, not which records to omit.

rowan.bradley wrote: Wed Dec 28, 2022 9:13 pm I have a column in the spreadsheet called Print which is set to "Yes" if that row is to be printed, and to blank if it is not.
Creating Mail Merge Documents From Text/CSV or Spreadsheets
Mail Merge requires a Writer document (the layout to be printed) and a Base document (the data source). You can connect to a spreadsheet when configuring your data source, but you must have a Base document. After connecting Base to your spreadsheet, create and save a query in the Base document to retrieve only the rows you want, perhaps something like:
SELECT YourFields FROM YourTable WHERE "Print" = 'Yes'

Instead of entering the SQL for the query, as I did above, you can use a wizard to build the query for you. Then, after creating your Writer document containing mail merge fields, use Edit → Exchange Database and select the query you created as the data source for the merge. Then use File → Print → Form letter? → Yes.

rowan.bradley wrote: Thu Dec 29, 2022 12:55 am Is there no "filter" facility …?
There is, though I think it will be more convenient to use a query unless you're only going to do this once. File → Print → Form letter? → Yes will display this dialog. I'd use Standard Filter, but you can use AutoFilter too. Read the documentation to learn more.
Using Mail Merge
Getting Started with Base
Standard Filter.gif
Standard Filter.gif (55.24 KiB) Viewed 4165 times

If this solved your problem please go to your first post use the Edit button and add [Solved] to the start of the Subject field. Select the green checkmark icon at the same time.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
Locked