Filter based on value in combo box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form with a combo box and a command button. I also have a bunch of
fields on the form that are bound to a query.

I want to be able to select an item in the combo box, click on the command
button and see all the related field in the rest of the form.

Just to experiment, I tried the following code on the button's On Click event:

Private Sub SearchCity_Click()
Me.Filter = "City = New York'"
Me.FilterOn = True
End Sub

This works fine. When I click on the button I see New York record.
I can't seem to find the right syntax to use in the above to use the value
selected in the combo box instead of stating the city explicitly:

Private Sub SearchCity_Click()
Me.Filter = "City = ComboBoxCity.Value"
Me.FilterOn = True
End Sub

Can someone help with the correct syntax? Thanks.
 
I have a form with a combo box and a command button. I also have a bunch of
fields on the form that are bound to a query.

I want to be able to select an item in the combo box, click on the command
button and see all the related field in the rest of the form.

Just to experiment, I tried the following code on the button's On Click event:

Private Sub SearchCity_Click()
Me.Filter = "City = New York'"
Me.FilterOn = True
End Sub

This works fine. When I click on the button I see New York record.
I can't seem to find the right syntax to use in the above to use the value
selected in the combo box instead of stating the city explicitly:

Private Sub SearchCity_Click()
Me.Filter = "City = ComboBoxCity.Value"
Me.FilterOn = True
End Sub

Can someone help with the correct syntax? Thanks.

The value must be concatenated into the string.
And, if the combo box value is a Text value you must surround the
value with single quotes.

Me.Filter = "City = '" & ComboBoxCity & "'"
 
Back
Top