VBA & Macro Problems

How to Create an Access Temporary Table from Multiselect List Box Items Using VBA

Elise WilliamsElise Williams Nov 3, 2026 870 views

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.

How to Create an Access Temporary Table from Multiselect List Box Items Using VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Define Database Variables

Open the VBA editor for your form and define your DAO database variables using 'Dim db As DAO.Database' and 'Dim varItem As Variant'.

2
Clear the Temporary Table

Add the execution command 'db.Execute "DELETE * FROM tblTempTable", dbFailOnError' to empty the table of any previous data.

3
Loop Through Selected Items

Create a loop using 'For Each varItem In Me.YourListBoxName.ItemsSelected' to iterate through every item the user highlighted.

4
Insert the Data

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 DAO VBA to Clear and Populate the Temporary Table
List Box Column Indexing: List box columns in Microsoft Access are zero-indexed. This means the first column from the left is referenced as Column(0), the second is Column(1), and so on up to Column(6) for a 7-column list box.
Free Microsoft Office alternative

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. 1. Download WPS Office: Install WPS Office to access Writer, Spreadsheet, Presentation, and PDF tools in one lightweight suite.
  2. 2. Organize Your Data: Open your exported data lists in WPS Spreadsheet to organize and clean the information.
  3. 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.
Fully compatible with Microsoft Excel (.xlsx) and Word (.docx) formats.Built-in Mail Merge features seamlessly connecting WPS Spreadsheet to WPS Writer.Free, lightweight application with a familiar, easy-to-navigate user interface.Smooth migration path for your existing Office documents without formatting loss.
QA img-9

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).