Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Want a record number text box beside each record

Status
Not open for further replies.

DanEaton

Technical User
Jun 24, 2002
60
CA
On my search form, my search results are in the detail of a continuous form. I want a text box to show the currentRecord beside each record. I tried to make a text box called txtCounter that would show this results. I put this in as the control source:

=[Me].[CurrentRecord]

This did not work. I tried some code that was supposed to make it work, but did not...I'm kinda stuck. Any help would be great.

-Dan Dan Eaton
deaton@caemachinery.com
 
Sounds like you want to enumerate the record source. Unfortunately the way how records are retrieved and stored physically can not make this happen easily.

However, there are work arounds. In the following example, I created a function when given a Form name and a record id, it returns the Absolute position of the record. There is an assumption that the record id is unique and is the first field in the form's recordset.

Code:
Public Function GetRecordPosition(FormName As String, MyRecID As Long) As Long
    Dim MyRST As Recordset
    
    Set MyRST = Forms(FormName).RecordsetClone
    MyRST.MoveFirst
    MyRST.FindFirst MyRST.Fields(0).Name & " = " & MyRecID
    GetRecordPosition = MyRST.AbsolutePosition + 1
    MyRST.Close
    Set MyRST = Nothing
End Function

On the form (continuous form), there is a text box control with the following control source value:
Code:
=GetRecordPosition("Form1", RecID)


This works great on small sets of data. Very slowly on larger sets.

-Doug
 
Almost worked, but the problem is that I have duplicate records taht come up (they aren't unique)...Thanks anyway
Dan Eaton
deaton@caemachinery.com
 
someone posted somthing like this recently
uses a static function
you may need to reset variable to zero each time you requery your record source

Did you try this

Public Function numrecs() As String
Static x As Integer
x = x + 1
numrecs = x
End Function

place
=numrecs()
in a textbox
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top