Calculated Control Field Criteria

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have the following form - trying to get a calculation based on form criteria:

Main Form = [Item #]

Detail = [Item #], [Bundle #], [Wgt] [Check Box]

I need to display "Sum of [Wgt]" but limited to the [Item #] from the main
form and only Records that the [Checkbox] is "Yes".

Any direction would be great.

Thanks
 
I have the following form - trying to get a calculation based on form criteria:

Main Form = [Item #]

Detail = [Item #], [Bundle #], [Wgt] [Check Box]

I need to display "Sum of [Wgt]" but limited to the [Item #] from the main
form and only Records that the [Checkbox] is "Yes".

Put a calculated field in the Query upon which the form is based by typing

WgtToSum: IIF([Check Box], [Wgt], 0)

Then on the Footer of the form put a textbox with a control source

=Sum([WgtToSum])

John W. Vinson [MVP]
 
aMack said:
I have the following form - trying to get a calculation based on form criteria:

Main Form = [Item #]

Detail = [Item #], [Bundle #], [Wgt] [Check Box]

I need to display "Sum of [Wgt]" but limited to the [Item #] from the main
form and only Records that the [Checkbox] is "Yes".


Since aggregate functions do not know about controls on the
form, you can not do the usual thing in the footer text box
with an expression like:
=Sum(IIf([Item #] = [main text box] And [Checkbox], Wgt, 0))

I think you can get the desired effect by using some code in
the main form text box's AfterUpdate event:

Dim xx As Variant
xx = [main text box]

[footer text box].ControlSource = "=Sum(IIf([Item #] =" _
& [main text box] & " And [Checkbox], Wgt, 0))

[main text box] = xx

For some unknown reason, in my test the main form text box's
value is reset when the footer text box's ControlSource is
set, so xx is used to save and restore its value.
 
John:

Excellent!

Thanks

--
A MACKENZIE, CMA, MBA


John W. Vinson said:
I have the following form - trying to get a calculation based on form criteria:

Main Form = [Item #]

Detail = [Item #], [Bundle #], [Wgt] [Check Box]

I need to display "Sum of [Wgt]" but limited to the [Item #] from the main
form and only Records that the [Checkbox] is "Yes".

Put a calculated field in the Query upon which the form is based by typing

WgtToSum: IIF([Check Box], [Wgt], 0)

Then on the Footer of the form put a textbox with a control source

=Sum([WgtToSum])

John W. Vinson [MVP]
 

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

Back
Top