Access - Not able to get record count

I am trying to open a table and count the records.  I keep getting record count is one.  However when i past the code of my select statement into a query i get the number which i am looking for which is 13.
I eventually would like to filter the table to reduce the results.

  1. Dim db As DAO.Database
  2. Dim rs, rs2 As DAO.Recordset
  3. Dim strSQL, RIGACCT, ClientID, dispname, comp, acctno, bal, exp, expdel, EXPDELDATE, eq, eqdel, EQDELDATE, tu, tudel, tuddate As String
  4. Dim pudate, credotes, newpudate As String
  8.        & "FROM CREDITREPORT;"
  9. Set db = CurrentDb
  10. Set rs = db.OpenRecordset(strSQL)
  11. With rs
  12.    Debug.Print .RecordCount
  13.    Debug.Print strSQL
  14.    Debug.Print db.OpenRecordset(strSQL).RecordCount
  15. End With
  16. Set rs = Nothing
  17. Set db = Nothing
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gustav BrockCIOCommented:
You can do:
With rs
   Debug.Print .RecordCount
   Debug.Print strSQL
   Debug.Print db.OpenRecordset(strSQL).RecordCount
End With

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You can also use DCOUNT:

The reason to use the DCount() suggestion over the DAO/Movelast is because with the DAO method, you are forcing Access to physically retrieve each row and bring it from the server to your local PC in order to count the fully populated LOCAL recordset.  With the DCount() method, the answer can be determined by the query engine simply looking at a table statistic and not retrieving any data at all.  The larger the row count, the more important the distinction.

Or, if you are welded to the DAO methodology, at least use a totals query:

Select Count(*) as RecCount from CREDITREPORT;

Then when you open the recordset, it contains a single row and that row contains your count.

The DCount() is essentially the same as the query above.  Both return a single value and both will be optimized to use table stats rather than being forced to retrieve individual rows.
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Any of the comment would provide the user with the record count
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.