473,386 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Form filtering problem

Seth Schrock
2,965 Expert 2GB
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

7 1995
dsatino
393 256MB
try adding me.requery to your code
Dec 2 '11 #2
patjones
931 Expert 512MB
Can you try reversing the order of lines 5 and 6 in your code?

Pat
Dec 2 '11 #3
Seth Schrock
2,965 Expert 2GB
Thanks Pat. I figured that it was something to do with the order of my commands.
Dec 2 '11 #4
NeoPa
32,556 Expert Mod 16PB
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
2,965 Expert 2GB
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
32,556 Expert Mod 16PB
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
2,965 Expert 2GB
Yes it does. Thanks.
Dec 3 '11 #8

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

Similar topics

3
by: Alex Ayzin | last post by:
Hi, I have a problem that might be easy to solve(possibly, I've just overlooked an easy solution). Here we go: I have a dataset with 2 datatables in it. Now, I need to do the following: if...
9
by: chris vettese | last post by:
On my subform I have a field in the footer that totals the value of a field. On the main form I have referenced this field. I'm using this field in a calculation on my main form. The problem...
3
by: Hans Karman | last post by:
I have a form (giving details of a person) and a subform (giving details of the person's assets). A search in the form for a particular name using the Find dialog box finds the wanted person. The...
3
by: Pierre Carter | last post by:
Hello, I'm using Response.Write to write text dynamically to a form. My problem is that the text sent to the page is not written at the top of the page, even if all margins are set to zero. I...
4
by: Bremanand | last post by:
Hi..Am doing Retailer software using VB 6.0 with ms-access.. Actually i have many form(sales entry form,purchase entry form ,stock form, etc..) in my project which all are in MDI except Log in...
1
by: prabuinet | last post by:
hi, I added a form as a control on another form. After adding i want the embedded form to have focus. I tried all combinations but its not working.. Do any one know how to do this. ...
5
by: LamSoft | last post by:
I've got some problem on some form submit problem. In a master page, there is a form tag with the "runat=server" attribute, and a ID called "myForm". In the contentPlaceHolder under that...
0
by: Lyn | last post by:
I have a problem using the form .Filter and .FilterOn properties which causes Access to crash (as detailed in a separate post). The form operates in continuous mode, displaying matching records...
3
NeoPa
by: NeoPa | last post by:
Cascaded Form Filtering CHAPTER 1 - TABLE OF CONTENTS (Including attached database) CHAPTER 2 - INTRODUCTION CHAPTER 3 - TABLE LAYOUT CHAPTER 4 - FORM LAYOUT CHAPTER 5 - FORM MODULE CHAPTER 6...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.