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]

Two simple changes synchronize the two listboxes.

The first is to set the RowSource of the right-hand listbox:

Select CourseID, Startdate
   From tblCourse
   Where CourseTypeID=lstCourse
   Order By Startdate;

The second is to make sure that the right-hand list box is updated every time that a new selection is made on the left. Put this code into the Click event of the listbox:

Private Sub lstCourse_Click()
   lstDates.Requery
   End Sub

This works because the Click code runs whenever the user changes to a new row in the list box - regardless of whether the change is made by a mouse click or the cursor keys.


Hints & tips

The textbox class in Visual FoxPro 9 has a new Autocomplete property which shows the user the previous values that have been entered in that textbox.
Autocomplete in VFP 9

Your Access database will look more impressive if you add custom toolbars...
Custom toolbars

FoxPro has always had functions to read and write files at a low level...
Foxpro low level file functions

More...
More pages of hints and tips for users of Microsoft FoxPro and Access databases.

Site Map