RecordSetClone.RecordCount vs RecordSet.RecordCount

S

Steve S

1. Researching a problem with RecordCount I see references to both Recordset
and recordsetclone. which one should I use when and why?

2. The use of Recordcount as the controlsource of a textbox on a form
causes a #Name error in AC2003. this same code works fine in AC2000.
RecordCount used in form modules seem to work OK in both versions.

Anyone have an idea what the problem might be?
 
M

Marshall Barton

Steve said:
1. Researching a problem with RecordCount I see references to both Recordset
and recordsetclone. which one should I use when and why?

2. The use of Recordcount as the controlsource of a textbox on a form
causes a #Name error in AC2003. this same code works fine in AC2000.
RecordCount used in form modules seem to work OK in both versions.

Anyone have an idea what the problem might be?


All of these worked for me in an A2003 text box expression
=Form.Recordset.RecordCount
=Recordset.RecordCount
=Form.RecordsetClone.RecordCount
=RecordsetClone.RecordCount

The clone of a recordset is a different recordset (connected
to the same data) so they can have different current
records. E.g. you can search the clone for a record without
messing with the form's current record. You need to know
when you should use the clone and when it is ok to use the
form's recordset directly.

Note that a form's RecordsetClone is automatically created
so there is little or no need to use Me.Recordset.Clone,
which will create a new recordset.
 
M

Marshall Barton

Steve said:
1. Researching a problem with RecordCount I see references to both Recordset
and recordsetclone. which one should I use when and why?

2. The use of Recordcount as the controlsource of a textbox on a form
causes a #Name error in AC2003. this same code works fine in AC2000.
RecordCount used in form modules seem to work OK in both versions.

Anyone have an idea what the problem might be?


This is not related to your posted question, but another
important point about RecordCount is that it returns the
*number of records accessed*. For all but table type
recordsets, this means it is only guaranteed to be >0 if
there are any records or 0 if there are no records. To
force all of a form's records to be "accessed" so
RecordCount returns the count of all of the form's records,
you would have to use a line of code (in the forms Load
event?):
Me.RecordsetClone.MoveLast
and, if you use RecordCount in a text box expression, you
probably should also requery the *text box*
 

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