Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

record count 2

Status
Not open for further replies.

hwkranger

MIS
Nov 6, 2002
717
US
assuming i have the following:

myrecord as recordset

myrecord = db.openrecordset("some table")

if i want to know how many records are in myrecordset, how do i get that number?

What object returns the number of records in a query/table.

I have a solution to this problem, but it involves LOOPing through every record, incrimenting some variable, and then I have the total number of records, but I"m sure there's an easier way.

thx Cruz'n and Booz'n always.
This post shows what little I do at work.
 
Dim RecCnt as Long

myrecord as recordset
myrecord = db.openrecordset("some table")

RecCnt = myrecord.RecordCount

Too easy, huh?
[pipe]
Anthony J. DeSalvo
President - ScottTech Software
"Integrating Technology with Business"
 
I've had trouble, and I've heard of others having trouble, with the recordcount property.

Some suggest doing a Rst.MoveLast prior to getting the record count.

I also believe that the record count property may not be set correctly if there are any .delete method invocations after the recordset is opened, but, like most things, I could be wrong.
 
beetee,
Your point is well taken.

I usually do a MoveLast, then a MoveFirst before getting the record count.

I would normally need the recordcount once (like for a For-Next loop, so any time this may take would be insignificant in the total process.

So in hwkranger's case I would have coded:

myrecord.MoveLast
myrecord.MoveFirst
RecCnt = myrecord.RecordCount

[2thumbsup]
Anthony J. DeSalvo
President - ScottTech Software
"Integrating Technology with Business"
 
It's Karmic Retribution for saying "Too easy, huh?"
 
I guess so, but that's what you get for taking Microsoft's product documentation as the Word! They should put a disclaimer like:

If the code doesn't work as defined, check the Tek-Tips forum!


[flush2] Anthony J. DeSalvo
President - ScottTech Software
"Integrating Technology with Business"
 
WOOOT THankyou guys!

I did try recordcount, but no matter how many records there were, it would report to me there were only 1. Unles there was 1, then it would say null.

Ok, So i'm going to try the movelast, movefirst :)

And it works!! Thanks! Cruz'n and Booz'n always.
This post shows what little I do at work.
 
Re:If the code doesn't work as defined, check the Tek-Tips forum!

lol! of course, that would double the size of their help files.
 
Record count function....

Public Function countOutstandingBank() As Long

countOutstandingBank = Nz(DCount("[Date]", "tblBank", ""), 0)

End Function

Then in code just refer to countOutstandingBank and you will have the record count.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top