record count problem

lana

Registered User.
Local time
Tomorrow, 00:16
Joined
Feb 10, 2010
Messages
92
Hi there,
I have a table which has 4 records. I use the followings to count the records:
Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset("tbl_calc")
rst.MoveLast
aaa = rst.RecordCount
rst.MoveFirst

this returns 44 instead of 4 !!!!!
Any ideas?
Thanks
 
You're seeing double? Too much alcohol?

Try this:

Code:
Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset("tbl_calc")
rst.MoveFirst
rst.MoveLast
aaa = rst.RecordCount
 
both will fail if the recordset it empty, try...
Code:
with currentdb.openrecordset(sql)
   if not .eof then .movelast
   GetCount = .recordcount
   .close
end with
To get a RecordCount you want to check for EOF, and you never need to MoveFirst.
 
Hi

Well actually I meant to write

Code:
Code:
Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset("tbl_calc")
rst.MoveLast
rst.MoveFirst
aaa = rst.RecordCount

That's how I normally do it
However, having read the last post from MarkK, I've checked and he is indeed right.
I've been doing an unnecessary MoveFirst line for years!
 
aaa = currentdb.OpenRecordset("select count(1) from tbl_calc")(0)
 
Thank you all.

Actually my own code works. I compacted the database then it worked?!

Table in question is a temp one and the data in it is cleared all the time.
Maybe something happens when data is deleted.

Thanks a lot.
 

Users who are viewing this thread

Back
Top Bottom