current / total number of records in Txtbox (1 Viewer)

stu_c

Registered User.
Local time
Today, 15:39
Joined
Sep 20, 2007
Messages
489
Hi all
I have a text box I want to show the current record number and total records so it reads "1 of 10" etc, I have got it to work on my main form but cant on my sub form another any suggestions?
it seems to recognise the first record as 0, so it reads "0 of 10" when I go to the next record it will go "1 of 10" etc any suggestions why?

Both on main for and sub form code
Code:
Public Function udfRecords(f As Form)
' RECORD NUMBERS
With f
            udfRecords = .CurrentRecord & " of " & IIf(.NewRecord, .CurrentRecord, .Recordset.RecordCount)

End With
End Function

the text box field control source
Code:
=udfRecords([Form])

many thanks
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:39
Joined
May 7, 2009
Messages
19,230
why not create a Class out of it, see this demo and the code on each form/subform.
 

Attachments

  • recordcount.zip
    64.8 KB · Views: 148

stu_c

Registered User.
Local time
Today, 15:39
Joined
Sep 20, 2007
Messages
489
Hello mate
thanks for the code, that genuinely am confused how that even works!, I cannot see how the boxes finds the data!
why not create a Class out of it, see this demo and the code on each form/subform.
 

Isaac

Lifelong Learner
Local time
Today, 07:39
Joined
Mar 14, 2017
Messages
8,777
Hi all
I have a text box I want to show the current record number and total records so it reads "1 of 10" etc, I have got it to work on my main form but cant on my sub form another any suggestions?
it seems to recognise the first record as 0, so it reads "0 of 10" when I go to the next record it will go "1 of 10" etc any suggestions why?

Both on main for and sub form code
Code:
Public Function udfRecords(f As Form)
' RECORD NUMBERS
With f
            udfRecords = .CurrentRecord & " of " & IIf(.NewRecord, .CurrentRecord, .Recordset.RecordCount)

End With
End Function

the text box field control source
Code:
=udfRecords([Form])

many thanks
I wonder if it has to do with the general context of the subform adding a new record? That gray area where it thinks it might be starting to create a new record, hence, it's something other than the first true record - and maybe calling it zero?
 

Users who are viewing this thread

Top Bottom