Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 694
  • Last Modified:

Count of checkboxes selected in subform

I have a form, FBRedemptionMainForm, with a subform, FBredeamProdQuerySubform, with a click box control, Selected.  I need to have a control in the footer of the main form that will total the records that are selected. Do I use the count function? How do I refer to the selected controls in the expression for the count function?
0
PetGuy
Asked:
PetGuy
  • 8
  • 5
1 Solution
 
mbizupCommented:
First, your checkbox should be bound to a Y/N field in the underlying table.

Then you can use the following in a textbox in the subform footer (include the = sign):

= ABS(Sum([YourYesNoFIeld]))

Open in new window


NOTE:  "YourYesNoFIeld" should be the name of the underlying Y/N field, not the name of your checkbox control.
0
 
Gregory MillerGeneral ManagerCommented:
I would suggest using the "On Click" event handler to test for whether the box is checked or unchecked and then increment or decrement a variable accordingly. The control in the footer can be tied to that variable and thus forced to refresh also in the On Click event.
0
 
mbizupCommented:
If you want to display that in the main form, you can set the Visible property of the textbox I described to False, and refer to it from the mainform (again in a textbox control source) like this:

= SubformControlName!Form!txtTotal
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mbizupCommented:
Slight correction to the above syntax - I'm mixing up periods and exclamation points.

Again suggesting to create the txtTotalSelected textbox in the subform footer (this is the easiest way to handle any filtering that may be applied in the subform).  The control source of a textbox in the subform footer would be:

= ABS(Sum([YourYesNoFIeld]))

Open in new window



Then to refer to it from the main form:

=[FBredeamProdQuerySubform].[Form]![txtTotalSelected]

Open in new window

0
 
PetGuyAuthor Commented:
The text field that does the counting in the footer of the subform is working fine. I am having trouble getting the text field in the footer of the main form to reference the the text control in the sub form.

Main form: FBRedemptionMainForm
Subform: FBRedeamProdQuerySubform
Text field with count on Subform:  BagTotalText

Control source value for text field in main form footer:  =FBRedeamProdQuerySubform!Form!BagTotalTxt

Result in main form footer text field: #Name?

What am I doing wrong?
0
 
mbizupCommented:
>>> Text field with count on Subform:  BagTotalText
>>> FBRedeamProdQuerySubform!Form!BagTotalTxt

Check your spelling on both.  Is it BagTotalText or BagTotalTxt (without the 'e' in text)?
0
 
PetGuyAuthor Commented:
BagTotalTxt is correct in both places. My error in the name in the last post
0
 
mbizupCommented:
Whoops... you didn't see the correction to the main form syntax in my post at http:#a39704905, and I missed it in your last post.


>>> FBRedeamProdQuerySubform!Form!BagTotalTxt!Form!BagTotalTxt

The ! following FBRedeamProdQuerySubform should be a "."

= FBRedeamProdQuerySubform.Form!BagTotalTxt

Open in new window

0
 
PetGuyAuthor Commented:
Changed, still getting same result
0
 
mbizupCommented:
The next thing to check is the subform control name: FBRedeamProdQuerySubform

Open your main form in design view, right-click on the very edge of the subform (the 'frame' that houses your subform), and select properties.

In the property sheet, what is shown for the "Name" property?  If this is different from FBRedeamProdQuerySubform, use the name from the property sheet instead.  (sometimes the 'subform control name' differs from the subform name as seen in the navigation pane)

If that doesn't help, can you post a sample of your database?  Just the relevant forms and tables, with any sensitive data masked or removed.
0
 
PetGuyAuthor Commented:
>>>= SubformControlName!Form!txtTotal

by = SubformControlName did you mean 1) the name of the subform or 2) the name of the control on the subform?

It is presently #1
0
 
PetGuyAuthor Commented:
that did it, it was FBRedeamProdQuery that changed an it worked.  

Thanks for all your help

wish i could get you 1000 points
0
 
mbizupCommented:
This is what I'm referring to -- sometimes the Name property of the control that 'houses' your subform is different from the name of the subform itself (which you see in the database window or navigation pane).  It is this 'subform control name' that you need in these these references, not the actual subform name (clear as mud, right? :-) )

Subform control name
0
 
mbizupCommented:
Oh - I missed your last post.  You've got it working - Excellent :-)
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 8
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now