Determine number of records in table

L

laavista

I'd REALLY appreciate help. I need to determine how many records are in a
table. The table is called t_Credits. The code I tried to use returns "1"
as the number of records (and there are 5 records right now).

Dim db As Database
Dim rstTCredits As DAO.Recordset
Dim longNumRecords As Long

Public Sub AddToCreditsUsed()

Set db = CurrentDb
Set rstTCredits = db.OpenRecordset("t_Credits", dbOpenDynaset)

longNumRecords = rstTCredits.RecordCount

MsgBox longNumRecords & " records in table TCredits."
 
K

Ken Sheridan

If using a recordset force the complete set to load by calling the MoveLast
method of the recordset object before examining its RecordCount property.

A simpler alternative, however, would be:

longNumRecords = DCount("*", "t_Credits")

Ken Sheridan
Stafford, England
 
B

Bob Quintal

There's a simpler way to get the number of records in a table:
DLookup("*","t_Credits")
You blew away what was otherwise a good response.
DCount("*","t_Credits") is what you should have written.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top