Calculated field in subform

reburton

Registered User.
Local time
Today, 04:31
Joined
Nov 4, 2013
Messages
46
I have an invoice form named frmInvoice. It contains a subform named subInvDetails. I am trying unsuccessfully to transfer a calculated subtotal from a text box in subInvDetails to a total in a text box in frmInvoice. Is there a way to do this? I have tried everything I can think of but I can't seem to make it happen.

To be more precise, I have a textbox which is a calculated value ([Rate]*[Hours]) named txtSubTotal in the sub form. In the main form I have a field named txtTotal. I thought that setting the Default Value of txtTotal to =Sum([Forms]![subInvDetail]![Subtotal]) was the right way to it, but the value of txtTotal remained zero. I have also tried using =Sum([Forms]![subInvDetail]![Subtotal]) as txtTotal's Control Source, but that didn't fit my needs or seem like the right way to do it. It didn't work anyway.

Can anybody help me?:confused:
 
Last edited:
Just calculate this on the main form, independently of the sub form . . .
Code:
=DSum("Rate * Hours", "tblInvDetails", "InvoiceID = " & [InvoiceID])
See? The data's in the table. Go straight there for your most robust and fastest result.
 
Thanks for replying! I really appreciate it. I tried to apply DSum and apparently I'm missing something. First I tried using a table as my domain:
=DSum([tblInvDetail]![Rate]*[tblInvDetail]![Hours],[tblInvDetail]) but it returned a zero. So, I looked DSum up on a website about Access VBA functions that I use. I saw that the domain could be a query. So, I used the Control Source query for the form. This is the formula I used: =DSum([Hours]*[Rate],[qryInvoice]). It also returns a zero. I tried both of them with and without a criteria statement. Can you see what I did wrong?
 
Yeah, the parameters you pass to DSum() should be strings, so you need to enclose them in quotes. Hours and Rate and qryInvoice are the names of things, fields, tables, as the case may be, and those are strings.
 

Users who are viewing this thread

Back
Top Bottom