Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Access - Not able to get record count

Posted on 2016-09-11
4
Medium Priority
?
49 Views
Last Modified: 2016-10-02
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
  5. strSQL = "SELECT CREDITREPORT.RIGACCT_FK, CREDITREPORT.CLIENTID_FK, CREDITREPORT.DISPLAYNAME, CREDITREPORT.COMPANYNAME, CREDITREPORT.ACCOUNTNUMBER, CREDITREPORT.BALANCE, CREDITREPORT.EXPERIAN," _
  6.        & " CREDITREPORT.EXPERIANDEL, CREDITREPORT.EXPDELDATE, CREDITREPORT.EQUIFAX, CREDITREPORT.EQUIFAXDEL, CREDITREPORT.EQDELDATE, CREDITREPORT.TRANSUNION, CREDITREPORT.TRANSUNIONDEL, " _
  7.        & "CREDITREPORT.TUDELDATE, CREDITREPORT.PULLEDDATE, CREDITREPORT.CREDREPORTNOTES, CREDITREPORT.NEWPULLEDDATE " _
  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
0
Comment
Question by:VGuerra67
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 51

Accepted Solution

by:
Gustav Brock earned 1000 total points (awarded by participants)
ID: 41793450
You can do:
With rs
   .MoveLast
   .MoveFirst
   Debug.Print .RecordCount
   Debug.Print strSQL
   Debug.Print db.OpenRecordset(strSQL).RecordCount
End With

Open in new window

/gustav
1
 
LVL 85

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points (awarded by participants)
ID: 41793555
You can also use DCOUNT:

DCOUNT("RIGACCT_FK", "CREDITREPORT")
0
 
LVL 39

Assisted Solution

by:PatHartman
PatHartman earned 500 total points (awarded by participants)
ID: 41796439
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.
0
 
LVL 85
ID: 41825212
Any of the comment would provide the user with the record count
0

Featured Post

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question