Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Passing a variable betweent forms

Posted on 2012-12-29
4
Medium Priority
?
206 Views
Last Modified: 2012-12-29
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?
0
Comment
Question by:MCaliebe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 38729318
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.
0
 
LVL 77

Expert Comment

by:peter57r
ID: 38729322
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,
0
 

Author Comment

by:MCaliebe
ID: 38729615
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.
0
 
LVL 85

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 38729623
Use an IIF statement, something like:

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

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question