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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting Records in a Table or Query 1

Status
Not open for further replies.

ActMod

Technical User
Aug 25, 2003
45
US
I am trying to set a variable in VBA equal to the number of records in a Query. Do you have to open the Query and use a command like NumRecords = rs.RecordCount, or is there a shortcut that does not require that the Query be opened?

For example: Nz(DSum("Field1", Query(i))) seems to work fine for aggregating the totals in Field1 without actually opening Query(i). Query(i) is just a string variable that equals the name of an existing Query. Is there a simliar command for just counting the number of records in a Query or Table?

Thank you for any help.

Jim
 
Hi!

Have you tried the DCount function with same syntax?

HTH Roy-Vidar
 
Thanks HTH Roy-Vidar,

I haven't tried "DCount". Can I use it with any Field to get the total number of records? Or, will there be a problem if there is an empty cell for the chosen Field?

Thanks much for your help.

Jim
 
I see. If I put "*" for Field it will count all records. Thanks very much. Very helpful!!

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top