473,471 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

No records after a filter is set the second time.

8 New Member
I have VBA code (Access 2003) like this:

Private Sub SubName()
rs.Filter = ""
x = msgbox("Filter cleared. Number of records: " & rs.RecordCount")
rs.Filter = "SELECT * from [Table]"
rs.Sort = "Field1 ASC, Field 2 DESC"
x = msgbox("Filter set to " & rs.Filter & ". Number of records: " & rs.RecordCount")
End Sub


The recordset and connection are declared in the Declarations section of the form. Everything I'm doing is on the same form.

The FIRST time this sub is run, it works great. Any time after that, I get the full recordset when the filter is cleared, but no records when the filter is set again.

Any ideas?
Dec 6 '07 #1
6 6885
puppydogbuddy
1,923 Recognized Expert Top Contributor
I have VBA code (Access 2003) like this:

Private Sub SubName()
rs.Filter = ""
x = msgbox("Filter cleared. Number of records: " & rs.RecordCount")
rs.Filter = "SELECT * from [Table]"
rs.Sort = "Field1 ASC, Field 2 DESC"
x = msgbox("Filter set to " & rs.Filter & ". Number of records: " & rs.RecordCount")
End Sub


The recordset and connection are declared in the Declarations section of the form. Everything I'm doing is on the same form.

The FIRST time this sub is run, it works great. Any time after that, I get the full recordset when the filter is cleared, but no records when the filter is set again.

Any ideas?
Sheree,

I think you need to turn the filter on and off, in addition to settting the filter's value, Try it this way:

Private Sub SubName()
rs.Filter = ""
rs.FilterOn = False
x = msgbox("Filter cleared. Number of records: " & rs.RecordCount")
rs.Filter = "SELECT * from [Table]"
rs.FilterOn = True
rs.Sort = "Field1 ASC, Field 2 DESC"
x = msgbox("Filter set to " & rs.Filter & ". Number of records: " & rs.RecordCount")
End Sub
Dec 6 '07 #2
Sheree
8 New Member
FilterOn is a property of the form (Microsoft Documentation).
My recordset is not part of the form, and does not have a FilterOn property. It is declared like this:

Public cn As ADODB.Connection
Public rs As ADODB.Recordset

Private Sub Form_Load()
Set cn = CurrentProject.AccessConnection
Set rs = New ADODB.Recordset
Set rs.ActiveConnection = cn
End Sub
Dec 6 '07 #3
puppydogbuddy
1,923 Recognized Expert Top Contributor
FilterOn is a property of the form (Microsoft Documentation).
My recordset is not part of the form, and does not have a FilterOn property. It is declared like this:

Public cn As ADODB.Connection
Public rs As ADODB.Recordset

Private Sub Form_Load()
Set cn = CurrentProject.AccessConnection
Set rs = New ADODB.Recordset
Set rs.ActiveConnection = cn
End Sub

Sheree,

Ok since you have the documentation handy... how about the ApplyFilter method? If that is not valid method, then the only other thing that comes to mind is to use Null instead of "" when clearing out your filter...
Dec 6 '07 #4
Sheree
8 New Member
That didn't seem to do much of anything.

I even switched it around and pointed to my table as a data source in the GUI, using "Me.Recordset" instead of 'rs', in order to expose the .FilterOn property... no dice. It won't filter at all.
Dec 6 '07 #5
puppydogbuddy
1,923 Recognized Expert Top Contributor
Sheree,
Ok, I did some checking ....this is what I think will fix your problem:

Setting a recordset's Filter property to adFilterNone restores the original recordset with which you were working:

So change:
rs.Filter = " "
To:
rs.Filter = adFilterNone

Also, you need to move the first two lines
rs.Filter = adFilterNone
x=...........................

to the last two lines of your sub. ....the reason being is that logically you would clear the filter and restore the original recordset after executing your rs.filter statement, not before.

Let me know what happens. Thanks.
Dec 6 '07 #6
Sheree
8 New Member
I had already tried using the adRecordsetNone constant. It didn't work any better than .Filter = "".

For a completely unrelated reason (needing to move the backend database to different locations to take it from home to work, etc.), I decided to use VBA to link my tables... and when that was completed, the original code, with no modification, started working flawlessly.

I guess I'm totally stumped by that one, but whatever... It works.

Oh, and for the record, the reason why the filter gets cleared at the beginning and not at the end, is because the subroutine is linked to a "search" button... meaning after I use the button to get my filtered records, i still have the filtered records until the next thing needs to cancel the filter, so my rs.Filter = "" is fine where it is, kthx.
Dec 6 '07 #7

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

Similar topics

3
by: Jason | last post by:
I am trying to filter records in a primary form based on records in related tables. The data in the related tables is being displayed in the primary form through subforms. To be more specific, I...
6
by: Matt K. | last post by:
Hi there, I have a form in an Access project that contains a subform which displays the results of a query of the style "select * from where = #a certain date#". In the main part of the form...
1
by: Dave | last post by:
I have a form which is based on a table (a) with over 6000 records.I have a button on this form which will open another form with related data from another table (b). What I want to do is open the...
6
by: Robin S. | last post by:
**Eric and Salad - thank you both for the polite kick in the butt. I hope I've done a better job of explaining myself below. I am trying to produce a form to add products to a table (new...
1
by: Rinee | last post by:
Hi, I have a database of a bunch of contractors who have signed a safety agreement with us, their contact info, their insurance info, etc. Each was assigned an ID number as the main key. Each...
1
by: hackerslacker | last post by:
I have an ordering form that use two combo boxes to filter down the records of a Products table. This worked fine with the after_Update of the first filtering the records and creating the...
3
by: melnhed | last post by:
---Report the current filtered records from a Form--- Hello All, I've seen this topic discussed before, but the solution described then doesn't work in my particular case. My Config: ...
2
by: srusskinyon | last post by:
I need some help getting unique records from our database! I work for a small non-profit homeless shelter. We keep track of guest information as well as what services we have offered for...
6
by: BEETHOVEN | last post by:
I have an option group called Issue_Type on my main form F1_Member_Demographics_Main. When I select one of the 3 options on the main form from the option group Issue_Type I want to limit the sub...
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
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
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.