AOB
Registered User.
- Local time
- Today, 19:35
- Joined
- Sep 26, 2012
- Messages
- 637
Hi there,
I have a form with two listboxes. Both are extended multi-select in nature and query-driven from two separate tables. There is a one-to-many relationship between these two tables (i.e. each 'parent' item in the first table can have multiple 'child' items in the second table; they are related via a common identifier)
I want to set up my listboxes so that when a user selects one item from the 'parent' listbox, the 'child' listbox is populated only with options for that selection. Similarly, if multiple items are selected from the 'parent' listbox, the 'child' listbox is populated with the options across all of those selected items.
So for clarity, let's call the two listboxes lstParent and lstChild and the respective tables tblParent and tblChild.
So I have as the RowSource for lstParent :
And the RowSource for lstChild :
But lstChild is never populated?
I tried adding this :
But no effect.
Any suggestions as to how I can achieve this?
(Am aware I could use the AfterUpdate event of lstParent to loop through the selected items and construct the query for lstChild with VBA using a SELECT...FROM...WHERE...IN syntax but I hoped something like this would be a bit neater?)
Any pointers?
Thanks
AOB
I have a form with two listboxes. Both are extended multi-select in nature and query-driven from two separate tables. There is a one-to-many relationship between these two tables (i.e. each 'parent' item in the first table can have multiple 'child' items in the second table; they are related via a common identifier)
I want to set up my listboxes so that when a user selects one item from the 'parent' listbox, the 'child' listbox is populated only with options for that selection. Similarly, if multiple items are selected from the 'parent' listbox, the 'child' listbox is populated with the options across all of those selected items.
So for clarity, let's call the two listboxes lstParent and lstChild and the respective tables tblParent and tblChild.
So I have as the RowSource for lstParent :
SELECT DISTINCT tblParent.Parent
FROM tblParent
ORDER BY tblParent.Parent
And the RowSource for lstChild :
SELECT tblChild.Child
FROM tblChild
INNER JOIN tblParent ON tblChild.ParentID = tblParent.ParentID
WHERE tblParent.Parent=[Forms]![frmMainForm]![lstParent]
ORDER BY tblChild.Child
But lstChild is never populated?
I tried adding this :
Code:
Private Sub lstParent_AfterUpdate()
Me.lstChild.Requery
End Sub
But no effect.
Any suggestions as to how I can achieve this?
(Am aware I could use the AfterUpdate event of lstParent to loop through the selected items and construct the query for lstChild with VBA using a SELECT...FROM...WHERE...IN syntax but I hoped something like this would be a bit neater?)
Any pointers?
Thanks
AOB