# Mail Merge

> Merge database records into Marked Text Fields of a template with TXTextControl in Visual Basic 6, print queued records and let users build templates.

- **Product:** TX Text Control ActiveX
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control ActiveX > Mail Merge
- **514 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-activex/mail-merge/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-activex/mail-merge/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-activex/mail-merge/llms-full.txt

---

Mail merge inserts the contents of database fields at specified positions of a previously prepared document, the template. With TX Text Control ActiveX, these positions are Marked Text Fields, and a Visual Basic sample program in three parts shows how to fill them from a database, print the merged documents and let users build templates of their own.

Storing a whole document in a database is a different task: [Connecting to Databases](https://docs.textcontrol.com/tx-text-control-activex/mail-merge/databases/llms-full.txt) shows how to save the entire contents of a `TXTextControl` in one database field.

### How the Sample Program Is Organized

Each part of the sample extends the previous one, and each has its own project in the *Samples\\vb6\\MailMerge* directory:

1. **Merging Database Data and Text** loads a template, browses the records of a database and merges the current record into the Marked Text Fields of the template.
2. **Printing More Than One Record** adds a print queue and prints the queued records with a hidden `TXTextControl`.
3. **Dynamic Template Generation** lets the user select a database and insert its fields into the template, and saves the database name with the template.

### Find the Right Page

| If you want to | Read |
|---|---|
| Fill the fields of a template with a database record | [Merging Database Data and Text](https://docs.textcontrol.com/tx-text-control-activex/mail-merge/merging-data/llms-full.txt) |
| Print several records in the background | [Printing More Than One Record](https://docs.textcontrol.com/tx-text-control-activex/mail-merge/multiple-records/llms-full.txt) |
| Let users insert database fields into a template | [Dynamic Template Generation](https://docs.textcontrol.com/tx-text-control-activex/mail-merge/dynamic-templates/llms-full.txt) |
| Store a complete document in a database field | [Connecting to Databases](https://docs.textcontrol.com/tx-text-control-activex/mail-merge/databases/llms-full.txt) |
| Learn how Marked Text Fields work | [Marked Text Fields](https://docs.textcontrol.com/tx-text-control-activex/document-editor/fields/llms-full.txt) |

### Pages in This Section

- [Merging Database Data and Text](https://docs.textcontrol.com/tx-text-control-activex/mail-merge/merging-data/llms-full.txt): find template fields by name and fill them with the data of a record.
- [Printing More Than One Record](https://docs.textcontrol.com/tx-text-control-activex/mail-merge/multiple-records/llms-full.txt): queue records and print each merged document.
- [Dynamic Template Generation](https://docs.textcontrol.com/tx-text-control-activex/mail-merge/dynamic-templates/llms-full.txt): build a layout editor for templates of any database.
- [Connecting to Databases](https://docs.textcontrol.com/tx-text-control-activex/mail-merge/databases/llms-full.txt): save and retrieve documents as RTF in a database field.

---

## In This Section

- [Connecting to Databases](https://docs.textcontrol.com/tx-text-control-activex/mail-merge/databases/llms-full.txt): Save and load TXTextControl documents as RTF in a database text field with SaveToMemory, LoadFromMemory and DAO in Visual Basic 6, and pick a compact format.
- [Dynamic Template Generation](https://docs.textcontrol.com/tx-text-control-activex/mail-merge/dynamic-templates/llms-full.txt): Build a Visual Basic 6 mail merge layout editor: insert fields of any database into a template, create labels at run time and save the database name with Save.
- [Merging Database Data and Text](https://docs.textcontrol.com/tx-text-control-activex/mail-merge/merging-data/llms-full.txt): Fill the Marked Text Fields of a template with a database record in Visual Basic 6: find fields by FieldData name with FieldNext, set FieldText with DAO.
- [Printing More Than One Record](https://docs.textcontrol.com/tx-text-control-activex/mail-merge/multiple-records/llms-full.txt): Queue database records in a list box and print each merged document with a hidden TXTextControl in Visual Basic 6 using SaveToMemory and PrintPage.

---

## Nearby

- **Previous:** [Built-In Dialog Boxes](https://docs.textcontrol.com/tx-text-control-activex/document-editor/dialog-boxes/llms-full.txt)
- **Next:** [Merging Database Data and Text](https://docs.textcontrol.com/tx-text-control-activex/mail-merge/merging-data/llms-full.txt)
