Correct Syntax for Function Call

K

Ken Hudson

I have a form with a sub form.
I have an object on the main form that is bound to the Ward_ID field in a
table. The object's name is txt_Ward_ID.

I have another text box ("Totals") on the form that I want to populate using
a function. The function does a sum of data entered through the sub-form.
When I use:

=fnTtlCost(Forms!frmWards!Ward_ID)

the "Totals" text box object on the main form automatically updates whenever
the source data on the sub form changes.

For some reason I thought that I could or had to reference the objects's
name in the function, not the bound field name, when I used the function.

=fnTtlCost(Forms!frmWards!txt.Ward_ID)

But the above does not automatically update the "Totals" box as data is
changed on the form.

Am I correct that the way to get the "Totals" to change dynamically is to
use the bound object's name?
 
D

Dale Fye

Ken,

If I understand properly, you are entering the data in the subform, but want
the "Totals" textbox in the main form to get updated each time you add a
record to the subform.

If that is correct, try something like the following in the AfterUpdate
event of the subform.

Private Sub Form_AfterUpdate

me.Parent.txt_Totals.requery

End Sub

--
HTH
Dale

email address is invalid
Please reply to newsgroup only.
 
K

Ken Hudson

Hi Dale,
Thanks for the reply.
Requery will work, but I believe that I don't have to add that code to
populate the Totals box the way the function is set up.
In my testing so far, the Totals box is automatically updated without the
need for a requery as long as the Ward_ID is passed to the function. It will
not work if I try to pass the Totals text box label.
I was looking for some confirmation that I had to do it that way.
I had a chance to ask a colleague about it and he said that I could use the
label if I passed the label property (i.e. value) to the function.
At this moment I am satisfied with the design.
Thanks again for the feedback.
 

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