Hi...
I want to count the amount of records matching my filtering...
I wrote:
sql_volume = "SELECT meetoefeningen.Meetgroep FROM meetoefeningen WHERE
meetoefeningen.Meetgroep=1;"
Set TB_volume = db.OpenRecordset(sql_volume)
volume = TB_volume.RecordCount
Voule always returns 1
What am I doing wrong?
Thanks
> Hi...
> I want to count the amount of records matching my filtering...
[quoted text clipped - 8 lines]
>
> What am I doing wrong?
The RecordCount in a Recordset is not accurate until you do a MoveLast.
However; instead of doing that it would be more efficient to use a SQL statement
that does the count...
sql_volume = "SELECT Count(*) " & _
"FROM meetoefeningen " & _
"WHERE Meetgroep=1"
Set TB_volume = db.OpenRecordset(sql_volume)
volume = TB_volume.Fields(0)

Signature
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Jean-Paul De Winter - 25 Nov 2006 17:55 GMT
Perfect... thank you both
JP
Rick Brandt schreef:
>> Hi...
>> I want to count the amount of records matching my filtering...
[quoted text clipped - 18 lines]
> Set TB_volume = db.OpenRecordset(sql_volume)
> volume = TB_volume.Fields(0)
The RecordCount is the number of records accessed so far.
When first loaded, it will be 0 (if there are no records) or 1 (if there are
any.)
To get the full count, MoveLast.
The Move methods error if there is no record to move to, so:
Set TB_volume = ...
If TB_Volume.RecordCount > 0 Then
TB_Volume.MoveLast
End If
Debug.Print TB_Volume.RecordCount
For more info, see:
Traps Working with Recordsets - 10 common mistakes
at:
http://allenbrowne.com/ser-29.html

Signature
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
> Hi...
> I want to count the amount of records matching my filtering...
[quoted text clipped - 9 lines]
> What am I doing wrong?
> Thanks