Main form - Sub form

D

darv2020

I have a main form with a subform of another table in it.
Is there a simple Dcount that can give me results in the main form?
I want to count how many "vacation day" there is in the sub form and
show the result in the main form.

This works but brings back all records "Vacation day" in the table
instead of just the records on the selected subform.

=DCount("[Time Off]","time off table","[Time Off] = 'Vacation Day'")

newbie! be gentile...
 
T

tina

add an unbound textbox control to the subform's Form Footer section. (you
can make the control, and the section, invisible - and you can use the
footer section even if the form is in Datasheet view.) name the textbox
"txtTotalVac" and set the textbox's ControlSource property to

=Sum(IIf([Time Off] = "Vacation Day", 1,0))

next, add an unbound textbox control to the main form, and set its'
ControlSource property to

=[NameOfSubformControl].[Form]![txtTotalVac]

replace NameOfSubformControl with the correct name of the subform control,
of course; and note that SubformControl refers to the control on the main
form the "contains" the subform. to get that name, open the main form in
Design view, click ONCE on the subform to select it (still within the main
form), and look at the Name property in the Properties box.

hth
 
D

darv2020

add an unbound textbox control to the subform'sFormFooter section. (you
can make the control, and the section, invisible - and you can use the
footer section even if theformis in Datasheet view.) name the textbox
"txtTotalVac" and set the textbox's ControlSource property to

=Sum(IIf([Time Off] = "Vacation Day", 1,0))

next, add an unbound textbox control to themainform, and set its'
ControlSource property to

=[NameOfSubformControl].[Form]![txtTotalVac]

replace NameOfSubformControl with the correct name of the subform control,
of course; and note that SubformControl refers to the control on themainformthe "contains" the subform. to get that name, open themainformin
Design view, click ONCE on the subform to select it (still within themainform), and look at the Name property in the Properties box.

hth


I have amainformwith a subform of another table in it.
Is there a simple Dcount that can give me results in themainform?
I want to count how many "vacation day" there is in thesubformand
show the result in themainform.
This works but brings back all records "Vacation day" in the table
instead of just the records on the selected subform.
=DCount("[Time Off]","time off table","[Time Off] = 'Vacation Day'")
newbie! be gentile...

Works Perfect! Thank you!
 
T

tina

you're welcome :)


add an unbound textbox control to the subform'sFormFooter section. (you
can make the control, and the section, invisible - and you can use the
footer section even if theformis in Datasheet view.) name the textbox
"txtTotalVac" and set the textbox's ControlSource property to

=Sum(IIf([Time Off] = "Vacation Day", 1,0))

next, add an unbound textbox control to themainform, and set its'
ControlSource property to

=[NameOfSubformControl].[Form]![txtTotalVac]

replace NameOfSubformControl with the correct name of the subform control,
of course; and note that SubformControl refers to the control on themainformthe "contains" the subform. to get that name, open themainformin
Design view, click ONCE on the subform to select it (still within themainform), and look at the Name property in the Properties box.

hth


I have amainformwith a subform of another table in it.
Is there a simple Dcount that can give me results in themainform?
I want to count how many "vacation day" there is in thesubformand
show the result in themainform.
This works but brings back all records "Vacation day" in the table
instead of just the records on the selected subform.
=DCount("[Time Off]","time off table","[Time Off] = 'Vacation Day'")
newbie! be gentile...

Works Perfect! Thank you!
 

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

Top