lkirke
asked on
Record Counter within a Subfrom
Hello Experts,
I am chasing some code for a record counter within a subform as I have chosen NO for the Navigation Buttons witihin form properties. The subform links to the form via a field named IMI.
Ultimately, it would be great to show this in a text box next to the command buttons I now use as navigation buttons.
LK
I am chasing some code for a record counter within a subform as I have chosen NO for the Navigation Buttons witihin form properties. The subform links to the form via a field named IMI.
Ultimately, it would be great to show this in a text box next to the command buttons I now use as navigation buttons.
LK
no code is needed.
you can put a text box in a subfom's "form Header" or "page header" with a control source of
=Count(a filed name)
i have attached a database for you to take a look at. in the sample i use the ID field so the control source for the text box is
=Count(ID)
: )
counter.accdb
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello Experts, tried some of the suggestions and tried to keep it fairly simple by not needing to call upon code or routines.
LambertHeenan: Unfortunately the code doesn't work.
However, I have attached an example where I get the record count of total records working, but am unsure as indicate the current record within the total number of records.
For example: 4 of 8, 5 of 8, 6 of 8 etc etc Example.mdb
LambertHeenan: Unfortunately the code doesn't work.
However, I have attached an example where I get the record count of total records working, but am unsure as indicate the current record within the total number of records.
For example: 4 of 8, 5 of 8, 6 of 8 etc etc Example.mdb
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
" Unfortunately the code doesn't work" are you sure you put the code in the sub form's Current event? This code certailing works for me. Is the form bound or not?
the code does work in the sample database he uploaded.
i suspect a control source was assigned and the code was used at the same time causing an error.
i suspect a control source was assigned and the code was used at the same time causing an error.
ASKER
Thank you to all Experts. Works as requested.
Private Sub Form_Current()
' Provide a record counter for using with
' custom navigation buttons (when not using
' Access built in navigation)
Dim rst As DAO.Recordset
Dim lngCount As Long
Set rst = Me.RecordsetClone
With rst
.MoveFirst
.MoveLast
lngCount = .RecordCount
End With
'Show the result of the record count in the text box (txtRecordNo)
Me.txtRecordNo = "Record " & Me.CurrentRecord & " of " & lngCount
End Sub