Apply filter to 2 fields at a time

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

Guest

Thanks for taking the time to read my question.

I have 2 combo boxes that I want to filter on. One is Person, the other is
location. Many people could be at many locations, and I want to filter the
form for a person at a single location, thus showing me all their visits to
the one place.

Here is what I have but it doesn't work:

Me.Filter = "Person = " & Me.Person.Column(1) & "," & "Location = " & "'" &
Me.Location.Column(0) & "'"

I can filter on either of them independantly, so it is not my code, I just
don't know how to put the two together.

Thanks,

Brad
 
Remove the comma, add an AND:
Me.Filter = "Person = " & Me.Person.Column(1) & " AND Location = '" &
Me.Location.Column(0) & "'"

It should evaluate to something like:
Me.Filter = "Person = 6 AND Location = 'The Village'" (an in joke for
fans of The Prisoner)

I also moved the single quote preceding the Location criteria so that it
follows = rather than being an unnecessary stand-alone.
If the Person criteria is a text value, it needs to be surrounded by single
quotes also.

HTH,
 
Thanks George, that was perfect.

Brad

George Nicholson said:
Remove the comma, add an AND:
Me.Filter = "Person = " & Me.Person.Column(1) & " AND Location = '" &
Me.Location.Column(0) & "'"

It should evaluate to something like:
Me.Filter = "Person = 6 AND Location = 'The Village'" (an in joke for
fans of The Prisoner)

I also moved the single quote preceding the Location criteria so that it
follows = rather than being an unnecessary stand-alone.
If the Person criteria is a text value, it needs to be surrounded by single
quotes also.

HTH,
 
Back
Top