Database development and training for Birmingham and the midlands
Specialists in Microsoft Access and Visual Foxpro database training and development
I am happy to hear from existing clients but I am taking no new calls.
Linking two Access listboxes
A single listbox is a good way of letting users select an entry from a table. Sometimes though, users' requirements are more complex and they need to be able to make the selection in two stages. The sample form opposite shows two list boxes. The left-hand box shows a choice of courses and the right-hand box shows the dates when the course selected by the user is running:
Two simple changes to the design will synchronize the listboxes and change the list of dates in the right-hand box whenever the user selects a new course in the left-hand box.
The first change is to set the RowSource of property the right-hand listbox so that it is based on the value of the left-hand listbox (named lstCourse here):
Order By Startdate;
The second is to make sure that the right-hand list box (named lstDates here) is updated every time that a new selection is made in the left-hand listbox. Put this code into the Click event of the left-hand listbox:
'-- Get the list of dates for the course selected.
This works because the Click code runs whenever the user changes to a new row in the Courses list box - regardless of whether the change is made by an actual mouse click or by the cursor keys. Either way, a new list of dates will be created in the right-hand listbox.