Passing a variable betweent forms

MCaliebe
MCaliebe used Ask the Experts™
on
Good morning,

I have a primary form with a subform housing records based on criteria in the header of the main form.

I also want to include a text box into my main form which would display the record count in the subform.  Can I have some ideas on how to handle this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Infotrakker Software
Most Valuable Expert 2012
Top Expert 2014
Commented:
Add a control to the Footer of the Subform, and set this as the ControlSource:

=Count(*)

Include the = sign too ...

Name that control "txSFCount"

Now in the mainform, add your table and set the ControlSource like this:

=Me.NameOfYourSubformCONTROL.Form.txSFCount

Note that NameOfYourSubformCONTROL is the name of the Subform CONTROL on the mainform, and may or may not be the same as the form you're using as a subform.
Add a textbox into the Form footer of the subform and set the controlsource to ...

=Count([anyNotNullField])
Say this textbox is called txtCount.

In the main form header add a textbox with the controlsource of...
=forms!mainformname!subformcontainername.Form!txtCount

subformcontainername is the name of the subform control on the main form that holds the subform.  It might be the same name as the subform but if they are different it is the subform (container) control name that must be used,

Author

Commented:
This gets me my count, however how do I get a 0 when no records exists.  Currently, the count text box in my sub form foote is blank and the reporting text box in my main form is Error.
Scott McDaniel (EE MVE )Infotrakker Software
Most Valuable Expert 2012
Top Expert 2014
Commented:
Use an IIF statement, something like:

=Iif(IsNumeric(Me.YourSubform.Form.txSFCount, Me.YourSubform.Form.txSFCount,0)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial