473,703 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

re-filtering subform

Scott Price
1,384 Recognized Expert Top Contributor
Hello again!

Running MS Access 2003 on WinXPproSP2.

Now I'm trying to re-filter my subform based on the currently shown Year field (the filter applied on open restricts to 15 records relating to the year 1990). I've added a command button to call the code designed to re-filter to the 13 or so records according to the next year (1991 in this case).

There may be other ways to do what I'm wanting (i.e. through pivottable views, etc., but I'd rather not go that direction until I've exhausted this one!)

Here is the VBA code I've written:

Private Sub cmdNextYear_Cli ck()
Dim CurrYearLkUp As Integer
Dim NextYear As Integer
Me!sfrmHistory. Requery
Me!sfrmHistory. SetFocus
Me!sfrmHistory! Year.SetFocus
CurrYearLkUp = Me!sfrmHistory! Year.Value
NextYear = CurrYearLkUp + 1
Me.sfrmHistory. Form.Filter = NextYear
Me.sfrmHistory. Form.FilterOn = True
End Sub

The code executes fine, but doesn't do what I want it to!

Instead of filtering to the NextYear (1991 in this example), it shows all records again with the (Filtered) tag next to the # of records.

I've tested using a watch to trigger a breakpoint when NextYear = CurrYearLkUp + 1 changes value. All values appear as they should be. The only apparent anomaly is that the value reported when you rest your mouse pointer over Me.sfrmHistory. Form.Filter = NextYear shows as a string (i.e. with ""'s around the figure 1991). The value for NextYear on the same line shows as 1991 without the ""s. (not sure if that should make a difference or not?!)

I've also tried first removing the filter in the lines of code immediately before reapplying it by using the line: Me.sfrmHistory. Form.FilterOn = False (Also tried using: DoCmd.RunComman d AcCmdRemoveFilt erSort with the same results)

This, however, makes no difference, as the result is the same.

Anyone able to help me out here?

Thanks in advance.

PS. the link to enable the scroll wheel feature in VBA's editor window is VERY welcome!!
Jul 4 '07 #1
2 2169
MikeTheBike
639 Recognized Expert Contributor
Hello again!

Running MS Access 2003 on WinXPproSP2.

Now I'm trying to re-filter my subform based on the currently shown Year field (the filter applied on open restricts to 15 records relating to the year 1990). I've added a command button to call the code designed to re-filter to the 13 or so records according to the next year (1991 in this case).

There may be other ways to do what I'm wanting (i.e. through pivottable views, etc., but I'd rather not go that direction until I've exhausted this one!)

Here is the VBA code I've written:

Private Sub cmdNextYear_Cli ck()
Dim CurrYearLkUp As Integer
Dim NextYear As Integer
Me!sfrmHistory. Requery
Me!sfrmHistory. SetFocus
Me!sfrmHistory! Year.SetFocus
CurrYearLkUp = Me!sfrmHistory! Year.Value
NextYear = CurrYearLkUp + 1
Me.sfrmHistory. Form.Filter = NextYear
Me.sfrmHistory. Form.FilterOn = True
End Sub

The code executes fine, but doesn't do what I want it to!

Instead of filtering to the NextYear (1991 in this example), it shows all records again with the (Filtered) tag next to the # of records.

I've tested using a watch to trigger a breakpoint when NextYear = CurrYearLkUp + 1 changes value. All values appear as they should be. The only apparent anomaly is that the value reported when you rest your mouse pointer over Me.sfrmHistory. Form.Filter = NextYear shows as a string (i.e. with ""'s around the figure 1991). The value for NextYear on the same line shows as 1991 without the ""s. (not sure if that should make a difference or not?!)

I've also tried first removing the filter in the lines of code immediately before reapplying it by using the line: Me.sfrmHistory. Form.FilterOn = False (Also tried using: DoCmd.RunComman d AcCmdRemoveFilt erSort with the same results)

This, however, makes no difference, as the result is the same.

Anyone able to help me out here?

Thanks in advance.

PS. the link to enable the scroll wheel feature in VBA's editor window is VERY welcome!!
Hi

You could try changing

Me.sfrmHistory. Form.Filter = NextYear

to

Me.sfrmHistory. Form.Filter = "Year = " & NextYear

Assuming 'Year' is the field name you are filtering on ?



MTB
Jul 5 '07 #2
Scott Price
1,384 Recognized Expert Top Contributor
Thanks Mike!

That fixed the problem... It occured to me also in the wee hours of the morning as I was trying to sleep but not having much luck :-( Hate when that happens :-)

Appreciate the help!
Jul 5 '07 #3

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

Similar topics

1
4310
by: Nel | last post by:
I have a question related to the "security" issues posed by Globals ON. It is good programming technique IMO to initialise variables, even if it's just $foo = 0; $bar = ""; Surely it would be better to promote better programming than rely on PHP to compensate for lazy programming?
4
6426
by: Craig Bailey | last post by:
Anyone recommend a good script editor for Mac OS X? Just finished a 4-day PHP class in front of a Windows machine, and liked the editor we used. Don't recall the name, but it gave line numbers as well as some color coding, etc. Having trouble finding the same in an editor that'll run on OS X. -- Floydian Slip(tm) - "Broadcasting from the dark side of the moon"
1
4098
by: Chris | last post by:
Sorry to post so much code all at once but I'm banging my head against the wall trying to get this to work! Does anyone have any idea where I'm going wrong? Thanks in advance and sorry again for adding so much code... <TABLE border="1" bordercolor="#000000" cellspacing="0"> <TR>
11
4005
by: James | last post by:
My form and results are on one page. If I use : if ($Company) { $query = "Select Company, Contact From tblworking Where ID = $Company Order By Company ASC"; }
4
18529
by: Alan Walkington | last post by:
Folks: How can I get an /exec'ed/ process to run in the background on an XP box? I have a monitor-like process which I am starting as 'exec("something.exe");' and, of course the exec function blocks until something.exe terminates. Just what I /don't/ want. (Wouldn't an & be nice here! Sigh) I need something.exe to disconnect and run in the background while I
1
3701
by: John Ryan | last post by:
What PHP code would I use to check if submitted sites to my directory actually exist?? I want to use something that can return the server code to me, ie HTTP 300 OK, or whatever. Can I do this with sockets??
10
4216
by: James | last post by:
What is the best method for creating a Web Page that uses both PHP and HTML ? <HTML> BLA BLA BLA BLA BLA
8
4416
by: Beowulf | last post by:
Hi Guru's, I have a query regarding using PHP to maintain a user profiles list. I want to be able to have a form where users can fill in their profile info (Name, hobbies etc) and attach an image, which will upload the record to a mySql db so users can then either view all profiles or query.. I.e. show all males in UK, all femails over 35 etc. Now, I'm not asking for How to do this but more what would be the best way? I've looked at...
1
3634
by: joost | last post by:
Hello, I'm kind of new to mySQL but more used to Sybase/PHP What is illegal about this query or can i not use combined query's in mySQL? DELETE FROM manufacturers WHERE manufacturers_id NOT IN ( SELECT manufacturers_id FROM products )
3
3486
by: presspley | last post by:
I have bought the book on advanced dreamweaver and PHP recently. I have installed MySQL and PHP server but am getting an error on the $GET statement show below. It says there is a problem with the variable $GET but $GET is not a variable, I thought it came from the page that calls the PHP file? if(($_GET)==""){ this gets an error
0
8758
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9251
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9121
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7867
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6588
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3123
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2450
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2069
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.