Ask Your Question

Fields in footer and header not being filled by mail merge

asked 2019-08-09 12:00:56 +0200 gravatar image

updated 2019-08-10 14:51:23 +0200


I have two fields in the footer of my .odt document referencing an entry in a Base database. When I print a form letter, those fields don't get populated tho. All other fields in the document (within the text body) do get populated. What could be the issue?

I have

<name>, <casenumber>

and I get


instead of

Smith, 123 X 45/67
edit retag flag offensive close merge delete



How do you connect to the database?

ajlittoz gravatar imageajlittoz ( 2019-08-09 14:43:58 +0200 )edit

View -> Data Sources. The database is an .odb file on my hard drive. In the end I produce a .pdf file by selecting Print -> Print a Form Letter -> Print to File.

I just ran a test and placed one variable from the database in the header, in the main text area and in the footer. Both the header and footer fields don't get populated, the field in the main text area is filled correctly. gravatar ( 2019-08-10 14:37:11 +0200 )edit

Header and footer are a bit special: they are outside main text flow. What is inside gets evaluated before the first content line in the page and after the last content line. Therefore, you may have a time conflict where the header is laid out before the record has been accessed by main text flow and the footer after access has been closed.

Last time I did such a thing, I generated a report in Base, not in Writer. The report generator is clean and clearly lets you control what is accessed and when. You know exactly which record you process. Have tried this path?

ajlittoz gravatar imageajlittoz ( 2019-08-10 15:26:46 +0200 )edit

Thanks so much for the insightful response! I don't know what you mean exactly by generating a report in Base. What I want to do is use a Writer template file with the mentioned fields in header and footer for evaluations of clients. I need to use Writer since I have to write the evaluations.

I've read that a possible workaround would be to use fields in header and footer that reference other fields in the document, which are within the main text flow. Basically the field <a> is defined as =<x>, and <x> is within the main text flow and references the Base entry. Is that possible? If so, how can I place such a field in the header? I don't know how to reference a field to another field. gravatar ( 2019-08-10 15:41:27 +0200 )edit

I don't think such an indirect reference would be the solution. However, you can make profit of the Document-kind of cross-references. Among these, you have the Chapter type. Then you pull your fields from the DB into a main text paragraph styled Heading n. You Insert>Field>Other FieldChapter - Chapter Name in your header and that should do the trick.

If it works, I'll make my comment an answer.

ajlittoz gravatar imageajlittoz ( 2019-08-10 15:55:21 +0200 )edit

I get your point and it would work in theory, but in practice it doesn't because my document is 50+ pages with real headings from level 1 to 3. If I put <name>, <casenumber> on the title page and style it as Heading 8 (9 and 10 are in use for other purposes), and then add a field in the footer of my two page styles (left page and right page as I print the document duplex), on for example page 25 it will show Heading 3 which is active on page 25. Seems like level n in the Document field reference includes higher headings, I don't know. A workaround for that would be to use Heading 1 style for the issue of this thread, but that would mean I have to restructure my complete setup. No other workarounds? I found out that instead of printing a form ...(more) gravatar ( 2019-08-10 16:27:21 +0200 )edit

What I didn't grasp is whether your letter is targeted towards a single <name> or if it is some kind of synthesis with each "chapter" dedicated to a <name>. Also mail-merge is intended to print many similar letters, each one for a single <name>. This seems contradictory with a 50+ pages letter.

With regard to Heading 8, Writer uses the largest existing Heading 1-7 if Heading 8 is not defined at the point of occurrence.

ajlittoz gravatar imageajlittoz ( 2019-08-11 08:07:53 +0200 )edit

I'm actually producing legal documents. I use mail-merge so I don't have to fill in the case data manually, I just enter them once into Base. I have about 30 different template files all connected to the database so whenever I need to write a certain letter or document, the mail merge allows me to quickly fill in all the data. The 50+ page document is a thorough legal statement for court and each individual file only refers to one entry in Base. gravatar ( 2019-08-12 09:29:41 +0200 )edit

OK, then you're in the typical mail-merge use case and your <name> does not change across the document.

ajlittoz gravatar imageajlittoz ( 2019-08-12 13:25:37 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2019-08-12 13:42:13 +0200

ajlittoz gravatar image

Here is an imperfect suggestion, but this is the best I could imagine according to the information provided (in my ignorance of a concrete example).

  • Somewhere near the beginning of your document (main text), create a paragraph with what you'd like to appear in your header or footer with the required field insertion(s). Add fixed text if you feel like it (the fixed text may also be typed in the header/footer at your convenience).

  • Select the range of characters containing the field(s) and create a bookmark for it: Insert>Bookmark and give it name "name_and_case" (without quotes) or any other name meaningful for you.

  • Create a paragraph style for this ancillary paragraph in which Hidden is checked in `Font Effects* tab. Style the paragraph.

    The paragraph being hidden will not print.

    I recommend that in Tools>Options, LibreOffice Writer>Formatting Aids Hidden text is checked so that the paragraph still displays on screen and you can easily edit it. This may need to enable View>Formatting Marks.

  • In the header, Insert>Cross-reference, type Bookmarks, reference to Reference, selection "name_and_case" and any other required fixed text.

You do that only once in your template. Then the letter will automatically work as any other mail merge document.

To show the community your question has been answered, click the ✓ next to the correct answer, and "upvote" by clicking on the ^ arrow of any helpful answers. These are the mechanisms for communicating the quality of the Q&A on this site. Thanks!

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-08-09 12:00:56 +0200

Seen: 217 times

Last updated: Aug 12 '19