Count of Records in a Subform

D

DEI

I have a form with a sub form. I would like to create a
control on the main form that counts the records in the
subform. Is there a way to use =Count function to do so?

Thanks in advance.
 
T

Theo

Add a text box. Make the control source:
=[subform name].Form.RecordsetClone.RecordCount
 
J

Jim Allensworth

I have a form with a sub form. I would like to create a
control on the main form that counts the records in the
subform. Is there a way to use =Count function to do so?

Thanks in advance.
Here is one way. Create the following function and use it in the
control source of the textbox to display a record count.

Private Function fSubFormRecCount() As Long
Dim frm As Form

Set frm = Me.SubformControlName.Form
frm.RecordsetClone.MoveLast
fSubFormRecCount = frm.RecordsetClone.RecordCount
Set frm = Nothing

End Function

Replace SubformControlName with yours and then put

=fSubFormRecCount()

in the Control Source of the textbox

- Jim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top