In addition to Albertโs suggestion, you may want to do this work inside the request itself so that it is โbootableโ. To do this, you will need to write a function that returns the value selected in the form combo box. It will be something like this:
Public Function ReturnMyCriterion() As Variant DoCmd.OpenForm "dlgGetCriterion", , , , , acDialog With Forms!dlgGetCriterion If .Tag <> "Cancel" Then ReturnMyCriterion = Nz(!cmbMyCombo, "*") End If Else ReturnMyCriterion = "*" End With Close acForm, "dlgGetCriterion" End Function
(when you open a form with the acDialog switch, the code pauses until the form is open or visible, to get the value from the combo box, you must set the .Visible property to False. Do this in the AfterUpdate event in the combo box or in OK button, you also need the Cancel button, which sets the form .Tag property to โCancelโ, and then sets the form. Vibible property for False: this is all a relatively standard approach to working with dialog forms in Access).
Then you will make a criterion in your query:
Like ReturnMyCriterion()
That is, if you want to return all records, if no value is selected in the list box.
source share