By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,599 Members | 1,325 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,599 IT Pros & Developers. It's quick & easy.

Form filtering problem

Seth Schrock
Expert 2.5K+
P: 2,951
I have a form that is viewed in split form. The form's Filter On Load property is set to No because I want it to show all records when opened. I have a button to filter the form based on the current CustomerID. My problem is that when I click on the button, nothing appears to happen. If I click on it a second time, then the filter works. Here is my code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnCustomerFilter_Click()
  2. Dim strCustomerID As Long
  3. strCustomerID = Me.CustomerID
  4.  
  5. Form.FilterOn = True
  6. Me.Form.Filter = "CustomerID=" & strCustomerID
  7.  
  8. End Sub
I'm wondering if I'm doing things in the wrong order causing the filter to be turned on at the wrong time, but I don't know for sure. I have a Clear Filter button that works fine by turning off the filter. If I clear the filters using this button, and then re-filter with the button listed above, then it works the first time. It only requires the filter button to be clicked twice right after the form loads. I'm sure the solution is simple (they all seem simple when I learn what it is), but I can't figure it out.
Dec 2 '11 #1

✓ answered by patjones

Can you try reversing the order of lines 5 and 6 in your code?

Pat

Share this Question
Share on Google+
7 Replies


dsatino
100+
P: 393
try adding me.requery to your code
Dec 2 '11 #2

patjones
Expert 100+
P: 931
Can you try reversing the order of lines 5 and 6 in your code?

Pat
Dec 2 '11 #3

Seth Schrock
Expert 2.5K+
P: 2,951
Thanks Pat. I figured that it was something to do with the order of my commands.
Dec 2 '11 #4

NeoPa
Expert Mod 15k+
P: 31,709
You obviously have a good answer there, but I frequently formulate my similar code as :

Expand|Select|Wrap|Line Numbers
  1. Me.Form.Filter = {Whatever - can even result in no filter}
  2. Me.Form.FilterOn = (Me.Form.Filter > "")
Dec 3 '11 #5

Seth Schrock
Expert 2.5K+
P: 2,951
To improve my education, what do you gain by using your code vs. what I had? I'm sure that you have a reason for doing it that way and I want to have my program be as well designed as possible.
Dec 3 '11 #6

NeoPa
Expert Mod 15k+
P: 31,709
Line #2 works appropriately (without any conditional code either) whether the filter is being set or cleared. FilterOn needs to be set correctly in both cases. Does that clarify?
Dec 3 '11 #7

Seth Schrock
Expert 2.5K+
P: 2,951
Yes it does. Thanks.
Dec 3 '11 #8

Post your reply

Sign in to post your reply or Sign up for a free account.