How to grab the record number?

  • Thread starter Thread starter Lythandra
  • Start date Start date
L

Lythandra

Hi there,

I have a continuous form that can have many thousands of records displaying
in it.

I have the Navigation Buttons active and thus the # of the record that has
the focus.

What I would like to do is grab that specific # and then use it in some
calculations.

For Example: There are 3000 total records in my form (based on the specific
query which can change) and I am on record #1500 within the form. I would
like to grab that 1500 number in code and use it for some calculations.

I have seen the command for it long ago but cannot find it for anything now.

Thanks
 
You can get the number you want using the Absolute Position property of the
recordset:

lngRecNo = Me.Recordset.AbsolutePosition

However, I caution you against using this number. Access does not have
record numbers. The number you will get is only relative to the current
recordset. If you filter the recordset or resort it or add records or delete
records, that number will change.

A better solution would be to capture the primary key of the record and use
that to get the values from the record for your calculations.
 
Aye I understand but it is only for temp calculations based on the specific
recordset being pulled from the table. Its relevant for the purpose of the
form.
 
Still not a good idea; however, you can use the AbsolutePosition method I
posted previously, then use the GotoRecord to position the form:

lngRecNo = Me.Recordset.AbsolutePosition
DoCmd.GoToRecord acDataForm, "MyFormName", acGoTo, lngRecNo
 
You've described "how" you want to do something.

If you'll describe "what" you want to accomplish (without resorting to
"how"), the newsgroup readers may be able to offer alternate approaches...

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
Back
Top