Recordset AbsolutePosition (1 Viewer)

MilaK

Registered User.
Local time
Today, 05:27
Joined
Feb 9, 2015
Messages
285
Hello,

I use the following subroutine to populate record number into a field on a continuous form. I've tried to put this code behind a button on the form and test it as I add more records to the form. It seems not to work well. Could someone please suggest another method?

Code:
Dim rs As DAO.Recordset
        Set rs = Me.Recordset
        Do While Not rs.EOF
          rs.Edit
          Debug.Print rs.AbsolutePosition
          rs!supporting_text = rs.AbsolutePosition + 1
          'Debug.Print rs.AbsolutePosition + 1
          rs.Update
          rs.MoveNext
        Loop
        rs.MoveFirst

thanks,

Mila
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:27
Joined
Oct 29, 2018
Messages
21,447
Hi Mila,

What is it doing or not doing? What do mean by “not work well?”
 

MilaK

Registered User.
Local time
Today, 05:27
Joined
Feb 9, 2015
Messages
285
The code is numbering each record on continuous sub-sub form. I put this code after-update event of text control so it would update the row number as a new row is entered. It doesn't always update right away (sometimes after entered several records).
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:27
Joined
Oct 29, 2018
Messages
21,447
Hmm, maybe try refreshing or requerying the form as well.

Just a thought...
 

MilaK

Registered User.
Local time
Today, 05:27
Joined
Feb 9, 2015
Messages
285
perhaps it was how I was referencing the form in the code:

This seems to work:

[Forms]![frm_total_report]![frm_reportable_comments].[Form]![frm_citations].[Form].Requery

vs.

Me.requery
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:27
Joined
Oct 29, 2018
Messages
21,447
Hi,

Glad to hear you got it sorted out. Good luck with your project.
 

MilaK

Registered User.
Local time
Today, 05:27
Joined
Feb 9, 2015
Messages
285
Never mind...it doesn't always populate the number. Any suggestion which event should fire the code?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:27
Joined
Oct 29, 2018
Messages
21,447
Sorry to hear it. I was going to suggest the Dirty event but not really sure about it. Are you able to post a sample db, so we can give it a try?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:27
Joined
May 7, 2009
Messages
19,227
use a counter instead:
Code:
Private m_bolLineUpdated As Boolean

Private Sub Form_AfterUpdate()
    Dim rs As DAO.Recordset
    Dim i As Long
    With Me.RecordsetClone
        Set rs = .openrecordset
        If Not (.bof And .EOF) Then .movefirst
            
        While Not .EOF
            i = i + 1
            .edit
            !supporting_text = i
            .update
            .movenext
        Wend
        
        Set rs = Nothing
    End With
    m_bolLineUpdated = True
End Sub

Private Sub Form_Current()
If Not m_bolLineUpdated Then Call Form_AfterUpdate
End Sub

EDIT: putting the code in the AfterUpdate of any control won't show the Numbering on New Record since the record is not yet saved.
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:27
Joined
Feb 19, 2002
Messages
43,196
You do realize that the sort order of the recordset affects the sequence number so if today the recordset is sorted by last name a record might be #286 but tomorrow if it is sorted by first name the record number might be #22.

What exactly is the purpose of renumbering the records on the fly? Records should be numbered as they are entered if you want to assign your own sequence number rather than use an autonumber. What is the point of constantly renumbering the records?
 

Users who are viewing this thread

Top Bottom