Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2004
    Posts
    10

    Unanswered: Problem with RecordCount property

    I have some very simple code but the RecordCount property doesn't seem to be returning the correct number of records in the record set.

    Here is my code:

    Dim db As Database
    Dim rs As Recordset
    Dim strSql As String
    Dim numRecords As Long

    ' SQL string to sum annual car sales
    strSql = "SELECT Table2.* From Table2;"

    Set db = CurrentDb() ' Open pointer to current database
    Set rs = db.OpenRecordset(strSql) ' Create recordset based on SQL

    numRecords = rs.RecordCount

    Do While Not rs.EOF
    Debug.Print ("MyId: " & rs![MyId])
    rs.MoveNext
    Loop
    rs.Close
    db.Close

    When I run this inside the debugger, numRecords is always 1 however the while loop is executed 26 times and there are 26 rows in my table. Any clues as to why the RecordCount property is not returning 26?

    Thanks,
    Becky

  2. #2
    Join Date
    Feb 2004
    Posts
    137
    Try this:
    Code:
    Dim db As Database
    Dim rs As Recordset
    Dim strSql As String
    Dim numRecords As Long
    
    ' SQL string to sum annual car sales
    strSql = "SELECT Table2.* From Table2;"
    
    Set db = CurrentDb() ' Open pointer to current database
    Set rs = db.OpenRecordset(strSql) ' Create recordset based on SQL
    
    Do While Not rs.EOF
    Debug.Print ("MyId: " & rs![MyId])
    rs.MoveNext
    Loop
    
    numRecords = rs.RecordCount     ' Do this after the loop
    
    rs.Close
    db.Close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •