Populate list boxes when a form field changes value

NielsE

Registered User.
Local time
Today, 09:05
Joined
Oct 10, 2005
Messages
21
I have three list boxes on a form (lstSubjectName, lstTargetGrName, lstCountryName). The list boxes are populated from queries
based upon tables that have a many-to-one relationship to the main table. The
queries are the following:

SELECT tblProjectSubject.ProjectID, tblProjectSubject.SubjectName
FROM tblProjectSubject
WHERE (((tblProjectSubject.ProjectID)=[Forms]![frmViewPro]![ProjectID]))
ORDER BY tblProjectSubject.SubjectName;

SELECT tblProjectTargetGr.ProjectID, tblProjectTargetGr.TargetgrName
FROM tblProjectTargetGr
WHERE (((tblProjectTargetGr.ProjectID)=[Forms]![frmViewPro]![ProjectID]))
ORDER BY tblProjectTargetGr.TargetgrName;

SELECT tblProjectCountry.ProjectID, tblProjectCountry.CountryName
FROM tblProjectCountry
WHERE (((tblProjectCountry.ProjectID)=[Forms]![frmViewPro]![ProjectID]))
ORDER BY tblProjectCountry.CountryName;

The form is based on the main table (tblProjects).
I want to re-populate/update the list boxes when the ProjectID on the form
changes. I have tried to use a macro (ProjectID_AfterUpdate) for requery of
the list boxes, but can't get it to work.
Any other solutions? Thanks.
Niels
 
Thanks. However, it does not work.
I have tried to attach the Me.lstCountryName to the ProjectID_AfterUpdate (does not work) and the ProjectID_OnChange (does not work either). When I scroll through the projects using the navigation buttons on the form, the Project ID on the form changes ok, but the lsit box content remains on the first record.

List box is an unbound control that gets its data from the following query:

SELECT tblProjectCountry.CountryName, tblProjectCountry.ProjectID, *
FROM tblProjectCountry
WHERE (((tblProjectCountry.ProjectID)=[Forms]![frmViewPro]![ProjectID]));

Any suggestions?
Niels
 
The events you mentioned only fire when the user makes the change, not when the control is changed programatically. Try putting your requery code in the Current event of the form.
 
Thanks RG. Works like a dream. You saved me again.
Niels
 

Users who are viewing this thread

Back
Top Bottom