|
-
Feb 21st, 2003, 05:59 AM
#1
Thread Starter
Junior Member
Is it possible to count the number of records in a filtered recordset?
Subject line says it all really.
-
Feb 21st, 2003, 07:01 AM
#2
Member
Hi,
If you have the recordset in code then .RecordCount should do the trick.
TC
-
Feb 21st, 2003, 08:56 AM
#3
Thread Starter
Junior Member
I've alreadytried that but it isn't allowed on a filtered recordset any more thoughts?
-
Feb 21st, 2003, 11:41 AM
#4
Member
Hi,
Don't have that problem myself, but how are you creating the recordset and what type of recordset is it?
TC
-
Feb 22nd, 2003, 01:48 AM
#5
Hyperactive Member
is your code as follows? ( i used Control)
Adodc1.Recordset.Filter = "EmployeeID<=" & Val(Text1.Text)
MsgBox Adodc1.Recordset.RecordCount
if your code is similar then deff. you can get record count.
If not Post your Code
-
Feb 22nd, 2003, 03:32 PM
#6
Thread Starter
Junior Member
I'm using DAO in Access 97
not at work at the moment but it goes something like
rst.filter = "select * where etc etc"
JFK
-
Feb 23rd, 2003, 07:34 AM
#7
Member
Hi,
Using DAO in Access and you're correct. You cannot use .RecordCount for what you want. (You can in VB though!)
Instead you need to create a new recordset based on the filtered original one. Alternatively just create a new recordset with the filter as a WHERE criteria!
Here is some code to show what I mean:
Code:
Dim db As Database
Dim rst As Recordset
Dim rstFilter As Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("TableName", dbOpenDynaset)
' Get the recordcount of the original recordset
rst.MoveLast
Debug.Print rst.RecordCount
' Set the filter on the original recordset
rst.Filter = "Enter Filter in here"
' Create a new recordset based on the filtered original
Set rstFilter = rst.OpenRecordset
' Get the recordcount of the new recordset
rstFilter.MoveLast
Debug.Print rstFilter.RecordCount
' Close it all down
rst.Close
rstFilter.Close
Set rst = Nothing
Set rstFilter = Nothing
Set db = Nothing
Hope it helps.
TC
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|