Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 3rd, 2004, 08:15 AM
Authorized User
 
Join Date: Mar 2004
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to get number of records in recordset

Hi guys

How to a find out how many records have been written to a recordset?

Thanks

Ciaran
 
Old March 3rd, 2004, 08:23 AM
Authorized User
 
Join Date: Mar 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

use Recordset.Recordcount

Lucian Preda
[email protected]

 
Old March 3rd, 2004, 08:50 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

http://www.adopenstatic.com/faq/reco...ternatives.asp
 
Old March 3rd, 2004, 09:18 AM
Authorized User
 
Join Date: Aug 2003
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Default

make sure that you set RecordSet.CursorLocation = adUseClient

otherwise the RecordCount always returns -1
 
Old March 3rd, 2004, 09:37 AM
Authorized User
 
Join Date: Mar 2004
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi guys

Do I just use

RecordSet.CursorLocation = adUseClient

in the code because I do get a count of -1 at the moment

Cheers

Ciaran
 
Old March 3rd, 2004, 10:40 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

First of all, are you using ADO or DAO?

From your other post it appears that you are using DAO.

The replies you have here are only valid for ADO. If you are using DAO in order to get an accurate record count you first need to move to the end of the recordset then call the Recordcount() method.

I would suggest testing for records first otherwise you will raise an error if there are no records.

Dim lCount As Long

If rs.BOF = True and rs.EOF = True Then
    ' You no there are no records
    ' You can return zero
    lCount = 0
Else
    ' Move to the last record
    rs.MoveLast
    ' I prefer to move back to the first
    rs.MoveFirst
    ' Now call the recordcount
    lCount = rs.Recordcount
End If

You can read the help files to learn more about the recordset objects methods and properties and how to use them.



Larry Asher
 
Old March 3rd, 2004, 10:59 AM
Authorized User
 
Join Date: Mar 2004
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot, I got it sorted

Cheers

Ciaran





Similar Threads
Thread Thread Starter Forum Replies Last Post
move to particular record number in recordset goodrags VB How-To 3 June 27th, 2006 09:11 PM
Show number of records Vision G Access 2 June 3rd, 2006 03:01 AM
total number of rows in a recordset lian_a Classic ASP Basics 2 February 8th, 2005 08:13 AM
retreiving a recordset with different records pablohoney Classic ASP Databases 3 September 3rd, 2004 02:58 PM
Number of records Pharasite Classic ASP Databases 4 July 1st, 2004 02:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.