Total records in a query

C

Charles Tam

I would like to retrieve the total records in a query. Is my following code
correct?
MS said to use the MoveLast command, but I have to install an error handle
if the recordset is empty.
....
Set qry = currentDatabase.OpenRecordset("Query1")
qry.MoveLast
debug.print qry.RecordCount
....
 
M

Marshall Barton

Charles said:
I would like to retrieve the total records in a query. Is my following code
correct?
MS said to use the MoveLast command, but I have to install an error handle
if the recordset is empty.
...
Set qry = currentDatabase.OpenRecordset("Query1")
qry.MoveLast
debug.print qry.RecordCount
...


You can check for an empty recordset by checking its
RecordCount property. It won't actually tell you how many
records there are, but it will only be zero when there are
no records.

Set qry = currentDatabase.OpenRecordset("Query1")
If qry.RecordCount > 0 Then qry.MoveLast
debug.print qry.RecordCount
 
C

Charles Tam

Thanks for your information.

Marshall Barton said:
You can check for an empty recordset by checking its
RecordCount property. It won't actually tell you how many
records there are, but it will only be zero when there are
no records.

Set qry = currentDatabase.OpenRecordset("Query1")
If qry.RecordCount > 0 Then qry.MoveLast
debug.print qry.RecordCount
 

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

Similar Threads


Top