473,396 Members | 1,998 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,396 software developers and data experts.

Reset filter, keep selection

40
I have a form which, depending from where it is opened, is filtered. I wish to have a way to remove filter so one has access to all records, but it is important that once filter is removed it does not jump to first record (It is single form). Is there a way to reset filter and keep the current record in form?
I hope this makes sense..
Oct 10 '07 #1
9 4588
FishVal
2,653 Expert 2GB
Hi, HyBry.

The following solution will work if you have visible control containing linked table primary key or other unique field.

form module
Expand|Select|Wrap|Line Numbers
  1. Private blnFilterRemoved As Boolean
  2. Private varID As Variant   'linked table unique field
  3.  
  4. Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType As Integer)
  5.  
  6.     If ApplyType = 0 Then   'filter is being removed
  7.         blnFilterRemoved = True
  8.         varID = Me.varID
  9.         'varID assumed to be a name of visible form control
  10.         'linked to varID table field
  11.     End If
  12.  
  13. End Sub
  14.  
  15. Private Sub Form_Current()
  16.  
  17.     If blnFilterRemoved Then
  18.         blnFilterRemoved = False
  19.         Me.varID.SetFocus
  20.         DoCmd.FindRecord varID
  21.     End If
  22.  
  23. End Sub
  24.  
Oct 10 '07 #2
HyBry
40
Thanks for the replay.. and sorry that mine is so late.
I did not fully understand the code you gave me and I did not get it to work, but it lead me to a different way to get it sorted:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.     If Me.FilterOn = True Then
  3.         Dim valFN As String
  4.         valFN = Me.FullName
  5.         Me.FilterOn = False
  6.         DoCmd.GoToControl "FullName"
  7.         DoCmd.FindRecord valFN
  8.     End If
  9. End Sub
  10.  
Does this seem OK or it can be problems in long run?
Oct 11 '07 #3
FishVal
2,653 Expert 2GB
Hi, HyBry.

Did you test the code? It looks like it will remove filter immediately after setting but will move form focus to the first filtered record, provides just some kind of record search. Is that what you've actually wanted?
Oct 11 '07 #4
HyBry
40
Hi FishVal,

Yes that is what I wanted, but only way I could find to do it was to use filter as it I am opening a new form.
Oct 11 '07 #5
FishVal
2,653 Expert 2GB
The code is Ok but I'm not sure it is a best idea to put it in Form_Current.
Did you try to put the code to Form_Open or Form_Load event handler?
Oct 11 '07 #6
HyBry
40
khmm... good idea... I did not try that..
Thanks... I am sure that will be much better... and maybe faster..
As I am still quite new to this it takes me some time to figure out where what should go. :D
Oct 11 '07 #7
HyBry
40
I need a bit more help on this please....
So I use this
Expand|Select|Wrap|Line Numbers
  1.     If Me.FilterOn = True Then
  2.     Dim valFN As String
  3.     valFN = Me.FullName
  4.     Me.FilterOn = False
  5.     DoCmd.GoToControl "FullName"
  6.     DoCmd.FindRecord valFN
  7.     End If
  8.  
in order to remove filter on the form in On_Load or On_Open events, and it works fine when the form is opened.
But if I click the button on the first form again, without closing target form first, it sets the filter again and as the form was already opened filter is not removed. I tried putting this in On_Current and that had different effect - it will work at first, when reloaded next time - no effect, reload again - filter removed, reload again - no effect and so on...
Any ideas how to solve this or the best bet is to make this modal (not preferred solution) so user is forced to close it?
Oct 12 '07 #8
FishVal
2,653 Expert 2GB
Hi, HyBry.

The simplest answer is: close the form before open.
Expand|Select|Wrap|Line Numbers
  1. DoCmd.Close acForm, "[Your form name]"
  2.  
Oct 12 '07 #9
HyBry
40
I wish I was as smart as You... it is so simple yet never entered my mind..
Thanks again :)
Oct 12 '07 #10

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

Similar topics

7
by: damjanu | last post by:
Hi All; I need little help. I have a datasheet form. I allow user to do 'filter by selection'. My form contains a column with values. As user changes selections, I want to calculate totals....
2
by: Terry | last post by:
I have cerated a Form, ExamsFrm, which is used to input details of exams taken at several Centres. It dosplays details from StudentTbl and has a SubForm which displays details from ExamsTble. I...
16
by: Nhmiller | last post by:
I already have a report designed under Reports. When I use filtering in Forms or Tables, I see no way to select that filtered list when I am in Reports, and there appears to be no way to do the...
6
by: Ralph2 | last post by:
Some time ago with a lot of help from this group I made a reasonably successful database to keep track of our shop drawings. However the searching mechanism is too complicated for the occasional...
0
by: mtermoul | last post by:
Hi, I'm trying to write an ASP.NET page using VS.NET 2003, Office 2003, Win 2000 but I keep gettin this error: "The message filter indicated that the application is busy" this is the code....
11
by: Bob | last post by:
I am in the process of upgrading an Access database to SQL Server (and climbing that learning curve!). The wizard happily upgraded all the tables and I can link to them OK using ODBC. The...
6
by: bammo | last post by:
MS Access 2003, Windows XP SP2, VBA I have a continuous form that allows edits and filters, but not deletions or additions. I filter the form based on combining selections the user makes in...
1
by: BSTAFFORD | last post by:
I need help. I have a form with a 5 comboboxes. the form also contains a subform query with the saved records from those 5 combobox categories. What I'd like to happen is as a new record is...
10
by: vanlanjl | last post by:
I have created a form that contain two combo boxes and two cmd buttons. The idea of the form is that the user will select a search parameter from each combo box then will click the first cmd button...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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...
0
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,...

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.