Filter a table by User Input using a macro

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
 
H

Howard Brody

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top