Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Count Record Set? (a2k (9.0.3821) SR-1 Jet 4.0 SP-6)

    If I execute the following code:

    Set rst = db.OpenRecordset("SELECT " & strExpression & _
    " FROM " & strDomain & _
    " WHERE " & strCriteria, _
    DB_OPEN_DYNASET)

    What command can I issue to determine the record count?

    Thanks, John

  2. #2
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Count Record Set? (a2k (9.0.3821) SR-1 Jet 4.0 SP-6)

    How about

    If rst.RecordCount = 0 Then

  3. #3
    3 Star Lounger
    Join Date
    May 2002
    Location
    Toronto, Ontario, Canada
    Posts
    314
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Count Record Set? (a2k (9.0.3821) SR-1 Jet 4.0 SP-6)

    Just a thought, but you may want to MoveLast before you check the RecordCount... I've always done it this way and I believe I read that it's possible to get an incorrect number without doing so... Someone will correct me if I'm wrong... <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    Set rst = ... blah, blah, blah...
    rst.movelast
    intCount = rst.recordcount

    ... and then move back to the first record if you need to iterate through them...

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Count Record Set? (a2k (9.0.3821) SR-1 Jet 4.0 SP-6)

    Depending on the references set in your database, a Recordset object can be a DAO recordset or an ADO recordset.

    For DAO recordsets, RecordCount called immediately after opening a recordset only indicates whether the recordset is empty or not: RecordCount = 0 indicates an empty recordset, > 0 a non-empty recordset. As mentioned, you must execute MoveLast to be able to obtain the correct RecordCount (and move back if you need to loop through the records.)

    For ADO recordsets, the cursor type is important. You can't get a record count in a Forward Only type recordset, so RecordCount will return -1. For Static and Keyset types, RecordCount returns the actual number of records (immediately after opening), and for Dynamic recordsets it returns -1 or the actual number of records.

  5. #5
    3 Star Lounger
    Join Date
    May 2002
    Location
    Toronto, Ontario, Canada
    Posts
    314
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Count Record Set? (a2k (9.0.3821) SR-1 Jet 4.0 SP-6)

    Thanks Hans...

    That's what I'd thought about DAO... I really have to start learning more about ADO... I'm letting myself get too comfortable with DAO... <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15>

Posting Permissions

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