Total records in a query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
....
 
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
 
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

Back
Top