How to Create an Access Temporary Table from Multiselect List Box Items Using VBA
Question details
The user needs to use Microsoft Access VBA to gather selected items from a multiselect list box, clear a temporary table, and insert the selected data across multiple columns for a Word mail merge.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Preparing selected form data from an Access multiselect list box to be exported or linked to a Word mail merge.
- Observed behavior
- The user requires the correct VBA syntax and workflow to delete existing records in the temporary table and programmatically insert the newly selected items.
Identify the exact name of your multiselect list box, ensure its Multi Select property is set to Simple or Extended, and verify the zero-indexed column structure before modifying your VBA code.
Use DAO VBA to Clear and Populate the Temporary Table
This method utilizes a VBA loop to iterate through the selected items in the list box, clears the existing temporary table, and safely inserts the new selections.
In Access, tables manage the data layer while VBA controls the logic. By using the ItemsSelected collection of your list box, you can dynamically capture user selections.
Executing a DELETE SQL statement before the loop ensures that the temporary table only contains the current selections, which is crucial for an accurate mail merge.
Open the VBA editor for your form and define your DAO database variables using 'Dim db As DAO.Database' and 'Dim varItem As Variant'.
Add the execution command 'db.Execute "DELETE * FROM tblTempTable", dbFailOnError' to empty the table of any previous data.
Create a loop using 'For Each varItem In Me.YourListBoxName.ItemsSelected' to iterate through every item the user highlighted.
Within the loop, construct an 'INSERT INTO tblTempTable' SQL string that maps the '.ItemData(varItem).Column(X)' properties from the list box to the corresponding table fields.

Use a Parameterized Saved Query for Mail Merge
Instead of clearing and refilling a temporary table, you can dynamically filter a saved query, which is often more efficient for Word mail merges.
Looking for a Lightweight Alternative to Microsoft Office?
While complex relational databases require specialized tools, many data tracking, reporting, and mail-merge tasks can be handled seamlessly with spreadsheets and word processors. WPS Office provides a free, lightweight, and highly compatible alternative with built-in mail merge capabilities.
- 1. Download WPS Office: Install WPS Office to access Writer, Spreadsheet, Presentation, and PDF tools in one lightweight suite.
- 2. Organize Your Data: Open your exported data lists in WPS Spreadsheet to organize and clean the information.
- 3. Start Mail Merge: Open WPS Writer, navigate to the References tab, and use the Mail Merge feature to link your spreadsheet data directly to your document.

Frequently Asked Questions
Why do I get a syntax error when inserting list box items into an Access table?
Syntax errors often occur when the text values from your list box contain special characters like apostrophes or quotation marks. To resolve this, use parameterized queries or DAO QueryDef parameters instead of directly concatenating strings in your SQL statement.
Can I use a query instead of a temporary table for a Word mail merge?
Yes. In many scenarios, using a saved query that dynamically filters based on your form selections is more efficient and easier to maintain than repeatedly creating, emptying, and refilling a temporary table.
How do I reference specific columns in an Access list box using VBA?
You can reference specific columns using the .Column(index) property of the list box. Because Access list boxes are zero-indexed, the very first column on the left is referenced as .Column(0).




