Filter a table by User Input using a macro

  • Thread starter Thread starter Brendan Mather
  • Start date Start date
B

Brendan Mather

I would like to allow the user to filter a list of contacts based on what
city the contacts are in. The user would input the city name into a text
box click a button and the new table would open with all the contacts from
that city. Can anyone help me out with this?

thanks
 
I would use a ComboBox instead. This way, you can use
the 'LimitToList' property to make sure the user selects a
City already in your table (use it as the source for the
ComboBox).

Also, you don't need to open a seperate copy of the
table. You can just filter your form:

In the AfterUpdate event of the ComboBox (cboCity) ,
filter the form for the selected city:

Private Sub cboCity_AfterUpdate()

' verify a city has been selected. If not, quit
If IsNull([cboCity]) Or [cboCity]="" Then
Exit Sub
End If

' build filter string
Dim strFilter As String
strFilter = "[City] = '" & [cboCity] & "'"

' apply filter
DoCmd.ApplyFilter , strFilter

End Sub

Hope this helps!

Howard Brody
 
Back
Top