Connecting Tech Pros Worldwide Help | Site Map

Why is RecordCount Returning Zero after .Filter Clause.

Newbie
 
Join Date: Sep 2009
Location: Nigeria
Posts: 2
#1: Sep 19 '09
i wrote this code. and kt is returning 0 even though there are records in the the recordset.
Expand|Select|Wrap|Line Numbers
  1. rsRGLV.Filter = "matno='" & MT & "'"
  2. kt = rsRGLV.RecordCount
What else can i use to get the number of records in a filtered recordset
best answer - posted by missinglinq
Try this
Expand|Select|Wrap|Line Numbers
  1. rsRGLV.Filter = "matno='" & MT & "'"
  2. rsRGLV.MoveLast
  3. rsRGLV.MoveFirst
  4. kt = rsRGLV.RecordCount
For some reason, never have figured out exactly why, sometimes you need to move to the end of the record set before the RecordCount registers correctly. I say sometimes because this is not always true.

Welcome to Bytes!

Linq ;0)>
missinglinq's Avatar
Moderator
 
Join Date: Nov 2006
Location: Richmond, Virginia USA
Posts: 2,991
#2: Sep 19 '09

re: Why is RecordCount Returning Zero after .Filter Clause.


Try this
Expand|Select|Wrap|Line Numbers
  1. rsRGLV.Filter = "matno='" & MT & "'"
  2. rsRGLV.MoveLast
  3. rsRGLV.MoveFirst
  4. kt = rsRGLV.RecordCount
For some reason, never have figured out exactly why, sometimes you need to move to the end of the record set before the RecordCount registers correctly. I say sometimes because this is not always true.

Welcome to Bytes!

Linq ;0)>
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,672
#3: Sep 19 '09

re: Why is RecordCount Returning Zero after .Filter Clause.


Quote:

Originally Posted by missinglinq View Post

For some reason, never have figured out exactly why, sometimes you need to move to the end of the record set before the RecordCount registers correctly. I say sometimes because this is not always true.

Access, like most RDBMSs, will get a number of records when a recordset is opened. It has a threshold number of records that it will grab at opening, for convenience of the user (whether showing the data on the screen or loading into storage within code). It cannot willy-nilly open every recordset and load it all into memory at once. Some datasets are simply too large for that to be practicable.

When getting the record count from a recordset it will return only that number that it already has knowledge of, as in what it has already grabbed. That is why reading to the end will always enable this code to work accurately.

To see this effect, simply open a very large table in your database and notice that the number of records is not displayed right-away. It will show if you click on the goto end button, or even if you leave it idle long enough. It does more reading ahead when it detects the system is idle for a while.
Newbie
 
Join Date: Sep 2009
Location: Nigeria
Posts: 2
#4: Sep 20 '09

re: Why is RecordCount Returning Zero after .Filter Clause.


thanks Neopa
I have tried the 4 lines of code yet, i have this error message
"either BOF or EOF is true, or the current recordhas been deleted.Requested Operation requires a current record"
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,672
#5: Sep 21 '09

re: Why is RecordCount Returning Zero after .Filter Clause.


You certainly have a problem Mary, but I doubt it's caused by the code (either yours or Linq's).

Unfortunately that's the only thing we have any knowledge of. We can't easily help with something we don't know about I'm afraid.
Expert
 
Join Date: Jul 2009
Location: KY
Posts: 244
#6: Sep 21 '09

re: Why is RecordCount Returning Zero after .Filter Clause.


MaryAboyade,

Are you applying this filter on a form? If so, do you see any records? The fact that you have zero for KT and an error when using linq's code, is because you just don't have any data.(If you try to move next on an empty dataset you get that exact error) If you are applying this filter to a form, try writing a query that applies the same logic you are attempting on the form, and see if any records are returned. If you still haven't figure out the issue, please post the entire sub routine that sets this filer.

Also, I just noticed you are setting the filter to "On"..
Expand|Select|Wrap|Line Numbers
  1. rsRGLV.Filter = "matno='" & MT & "'"
  2. rsRGLV.filterOn = True '---> This was missing
  3. kt = rsRGLV.RecordCount
  4.  
-AJ
Newbie
 
Join Date: Oct 2009
Posts: 1
#7: 3 Weeks Ago

re: Why is RecordCount Returning Zero after .Filter Clause.


~missinglinq
I signed up just to say THANK YOU! I spend the better part of a day messing with code trying to see why my recordcount wasn't what it was supposed to be, and your move to the end and back solved it. Thanks!
J
missinglinq's Avatar
Moderator
 
Join Date: Nov 2006
Location: Richmond, Virginia USA
Posts: 2,991
#8: 3 Weeks Ago

re: Why is RecordCount Returning Zero after .Filter Clause.


Glad we could help you, J!

This is why we place so much emphasis on posters using thread titles that clearly describe the question/problem, so that people coming along months or even years later can find solutions!

Welcome to Bytes!

Linq ;0)>
Reply