0
votes

I have two columns ImportDateOn and InventoryDate in the table [tbl E&O Main]. I create a combo box to navigate ImportDateOn and a list box to display InventoryDate. When I click on my combo box and the list box for InventoryDate should be filtered automatically. I set an AfterUpdate() event on the combo box as following:

Private Sub DateSelector_AfterUpdate()
   Forms![CtrlPanel]!InventoryDateList.Value = Null
   Forms![CtrlPanel].Requery
   Forms![CtrlPanel].Refresh
End Sub

Then in the datasource for the list box , my code is as following

SELECT [tbl E&O Main].InventoryDate 
FROM [tbl E&O Main] 
WHERE [tbl E&O Main].ImportDateOn=Forms![CtrlPanel]![DateSelector].[value] 
GROUP BY [tbl E&O Main]!InventoryDate; 

Please advise why the list box doesn't go with the combo box selection.

Design View Form Screen Shot

1
You need to requery the listbox not the form. Me.InventoryDateList.Requery - BitAccesser
Do you mean adding a vba code to the listbox ? why do I need to do it ? for refreshing ? - Laura X
Code stays in Private Sub DateSelector_AfterUpdate(), but requerys the listbox. See and accept Chris answer. - BitAccesser

1 Answers

1
votes
Private Sub DateSelector_AfterUpdate()
 Forms![CtrlPanel]!InventoryDateList.Value = Null
 Forms![CtrlPanel]!InventoryDateList.Requery
End Sub

This should do the trick.

@BitAccesser is correct, the requery command should be on your listbox not the form.

Requerying a form updates the data from the control source of the form, but does not requery other (Unbound) objects stored in the form. Since you only want to refresh the selections in the listbox, you don't even need to refresh or requery your form object.