Recordset.Recordcount

T

Tom

In a recent post I saw the following:

Me.Recordset.Recordcount

I have tried this and it seems to work in Access97 and AccessXP. I also tried:

Forms!MyForm.form.recordset.recordcount

and that seems to work. However, when I enter either in code, recordset comes up
as I type the code but recordcount does not. Is recordcount a legitimate
property of recordset and is this a reliable way of getting the count of the
records in a recordset?

Thanks for all comments!

Tom
 
T

Tom Wickerath

For some reason, the use of the ME keyword is keeping it from displaying "recordcount" in
intellisense. It will display this property if you refer to a variable that has been set
as a recordset, as long as you don't use the bang (!) notation. For example:

Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo ProcError

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Set db = CurrentDb()

strSQL = "SELECT * FROM tblCustomers;"

Set rs = db.OpenRecordset(strSQL)

If rs.RecordCount > 0 Then '<------ rs. produces the intellisense list, which
includes Recordcount.

etc.


Tom
_________________________________________

Doug,

Thanks for the response!

Why doesn't recordcount come up in intellisense?

Tom

___________________________________________________________

Yes, RecordCount is a valid property of both DAO and ADO recordsets.

As to its reliability, it's not guaranteed to be correct unless you've
retrieved all records. One approach is to do a .MoveLast before you access
the .RecordCount property.

--
Doug Steele, Microsoft Access MVP


___________________________________________________________


In a recent post I saw the following:

Me.Recordset.Recordcount

I have tried this and it seems to work in Access97 and AccessXP. I also tried:

Forms!MyForm.form.recordset.recordcount

and that seems to work. However, when I enter either in code, recordset comes up as I type
the code but recordcount does not. Is recordcount a legitimate property of recordset and
is this a reliable way of getting the count of the records in a recordset?

Thanks for all comments!

Tom
 
D

Dirk Goldgar

Tom said:
Doug,

Thanks for the response!

Why doesn't recordcount come up in intellisense?

It's because, oddly enough, the Recordset property of a form is not
defined as being of type Recordset, but rather simply as Object.
Therefore, the intellisense doesn't know that this property refers to a
Recordset *type* of object, and hence doesn't know what the properties
of the object are.

I assume that the reason the Recordset *property* is only defined as
type "Object", and not as a more specific type of object, is that it
could be either a DAO Recordset object or an ADO Recordset object,
depending on the circumstances. The property can't assume it's one or
the other.
 

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