How to Populate an Access Junction Table Using a Multiselect List Box
Question details
The user needs to populate a many-to-many junction table in a database using a multiselect list box to assign items, such as linking multiple athletes to a specific session.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Designing a user interface form to manage many-to-many relationships using a multiselect list box instead of a standard subform.
- Observed behavior
- Requires a method to execute insertions and deletions in the junction table based on list box selections, while noting the limitations of list boxes when additional attributes are needed.
Before modifying your database interface or adding new VBA scripts, make sure you have backed up your current Access database file to prevent accidental data loss during testing.
Use VBA in the List Box AfterUpdate Event
Write a VBA script to loop through the multiselect list box, dynamically adding selected items and removing deselected items from the junction table.
This method requires writing VBA code attached to the list box's AfterUpdate event. It is ideal when you only need to link two IDs without adding extra attributes to the junction table.
Open your Access form in Design View and select the multiselect list box you want to use for the selections.
Open the Property Sheet, navigate to the 'Event' tab, and click the ellipsis (...) next to the 'AfterUpdate' event to launch the VBA editor.
Write a VBA loop that iterates through the ItemsSelected collection of the list box to identify which rows have been highlighted by the user.
Inside the loop, use the CurrentDb.Execute method to run a SQL INSERT statement for newly selected items and a DELETE statement for unselected items against your junction table.
Save your VBA code, switch back to Form View, and test the selections to ensure the junction table updates correctly behind the scenes.

Use a Conventional Form and Subform (No VBA Required)
A simpler, code-free alternative that natively handles many-to-many relationships and easily allows for additional attributes in the junction table.
Manage Data Easily with WPS Office
While Microsoft Access is designed for complex relational databases, many everyday data tracking needs can be managed much more easily with WPS Spreadsheets. WPS Office is a lightweight, highly compatible alternative to Microsoft Office that lets you organize lists, analyze data, and create professional documents for free without needing to write VBA code.
- 1. Download the Installer: Visit the official WPS Office website and download the free installation package for your operating system.
- 2. Install WPS Office: Run the downloaded installer and follow the simple on-screen instructions to complete the setup.
- 3. Organize Your Data: Open WPS Spreadsheets to start managing your data lists, creating dropdowns, and analyzing information easily.

Frequently Asked Questions
Why shouldn't I use a multiselect list box for a many-to-many relationship?
Multiselect list boxes are fine for simple ID linking, but they become problematic if your junction table requires additional attributes (like tracking the date an item was added or an assigned role). A form/subform setup is much better suited for capturing those extra fields.
What is the ItemsSelected property in Access VBA?
ItemsSelected is a collection in VBA that contains references to the specific rows a user has highlighted in a multiselect list box. You can loop through this collection to extract the bound column values for database operations like INSERT or DELETE.
Can I link a list box directly to a junction table without using VBA?
No, a multiselect list box cannot automatically insert or delete records in a junction table just by having the user click on items. You must use VBA macros in events like AfterUpdate to programmatically write the changes to the database.




