Using Recordsets in ADO

G

Gary

I need to perform a select query on my local table,
tblAddress, in Access 2000. When I run the following
query using ADO, I keep getting -1 for the recordcount,
but there are over 3,000 records in the table. Is there
something wrong with the way I am opening the recordset?
Here is the code, Thanks:

Dim objConn As ADODB.Connection
Set objConn = CurrentProject.Connection
Dim strSQL As String
Dim strSQLAddress As String
Dim rsAddress As ADODB.Recordset

Set rsAddress = New ADODB.Recordset
rsAddress.Open "Select * from tblAddress", objConn
MsgBox "the numer of records are " &
rsAddress.RecordCount, vbInformation
rsAddress.Close
 
D

Dan Artuso

Hi,
From Help:
The cursor type of the Recordset object affects whether the number

of records can be determined. The RecordCount property will return -1 for

a forward-only cursor; the actual count for a static or keyset cursor; and either -1

or the actual count for a dynamic cursor, depending on the data source.



HTH

Dan Artuso, MVP
 
A

Amy Vargo

Hi,

My name is Amy Vargo. Thank you for using the Microsoft Access Newsgroups.
For recordsets and snapshots, Microsoft Access does not automatically
return the number of records that exist in the recordset. Rather, it
returns the number of records accessed.

To determine the exact number of records in a recordset or snapshot, use
the MoveLast method of the recordset object before checking the RecordCount
property.

I hope this helps! If you have additional questions on this topic, please
respond back to this posting.


Regards,

Amy Vargo
Microsoft Access Engineer


This posting is provided 'AS IS' with no warranties, and confers no rights.
You assume all risk for your use. © 2001 Microsoft Corporation. All rights
reserved.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top