Filtering using VBA

cpu22

New member
Local time
Today, 16:25
Joined
Jan 5, 2018
Messages
9
Hello again,

I'm trying to filter my recordset using a toggle button. The field I want to filter is called [Insurance]. It has only 2 possible choices, "UPMC" or "Highmark". While it's not the full functionality I want yet, I just want to be able to filter this toggle button for "UPMC" right now w/o using a text box. The code I used is:

Me.Filter = "Insurance = UPMC"
Me.FilterOn = True

This opens up a text box named "UPMC" then I type in "UPMC" and the filter works. Any way I can get it to filter for "UPMC" without a text box?

Thanks,
Christian
 
Me.Filter is a string. I (and the computer) know that because there are quote marks around it.

Inside that string you want to declare a string. You can't just use double quote marks because that will confuse the outside string as to where it starts/stops. So, use single quotes around the inner string portion of your string.

Me.Filter = "Insurance = 'UPMC'"
 
Me.Filter is a string. I (and the computer) know that because there are quote marks around it.

Inside that string you want to declare a string. You can't just use double quote marks because that will confuse the outside string as to where it starts/stops. So, use single quotes around the inner string portion of your string.

Me.Filter = "Insurance = 'UPMC'"

Thank you so much for your help. It's been a long time since I've used VBA so I apologize for the simple question.

Thanks again,
Christian
 
No apologizes necessary, that's what this forum is for. Plus its not really that intuitive of an answer.
 
No apologizes necessary, that's what this forum is for. Plus its not really that intuitive of an answer.

Now what would I do if I wanted to filter by more than one string at a time?
 
You would do multiple comparisons seperated by an OR:

"Field='X' OR Field='Y' OR Field='Z'"
 
You would do multiple comparisons seperated by an OR:

"Field='X' OR Field='Y' OR Field='Z'"

Actually I have another question please. So I have my form filtered by a few possibilities on the same field. Now I have an option button on the form, which I would like to use to filter on a different field. How can I filter on this additional field while keeping my original filter intact?

Thanks again,
Christian
 

Users who are viewing this thread

Back
Top Bottom