Solved

Passing a variable betweent forms

Posted on 2012-12-29
4
199 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
  • 2
4 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 125 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 84

Assisted Solution

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

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

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Tags from access to excel 3 31
Unrecognized Database Format 8 94
Authenticate Username & Password from MS Access to Active Directory 5 47
Search Form not Querying 2 12
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

862 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now