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 below shows one list box showing a choice of courses and a second box showing the dates when the selected course is running:

[Two list boxes linked together]

Two simple changes to the design will synchronize the two listboxes.

The first is to set the RowSource of the right-hand listbox so that it is based on the value of the left-hand listbox (named lstCourse here):

Select CourseID, Startdate
   From tblCourse
   Where CourseTypeID=lstCourse
   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:

Private Sub lstCourse_Click()
  '-- Get the list of dates for the course selected.   lstDates.Requery
End Sub

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 a mouse click or by the cursor keys. Either way, a new list of dates will be created in the right-hand listbox.

Access Tips

FoxPro Tips

General Tips

 

Related Items

Messagebox and its alternatives in Visual FoxPro

The standard Windows messagebox is only one way of getting information to the user.

Read More