dsum and update (requery)

B

beppe005

In a Form I have a textbox with a Dsum function which calculates the sum of
[Hours] enetered in a child subform.
My problem is that I cannot get the Dsum to be updated when I enter my
[hours], unless I use the key "F9".

The Dsum function works ok, is the update thing that I don't know how to
solve.

The structure is like this:
MasterForm, where there is the Dsum function
Subform01, linked to Masterform
Subform02, which is linked to subform01, with the field [hours]

The dsum funcion calculates the sum of [hours] with the same [MasterForm
ID].


TIA
Beppe
 
D

Dirk Goldgar

beppe005 said:
In a Form I have a textbox with a Dsum function which calculates the
sum of [Hours] enetered in a child subform.
My problem is that I cannot get the Dsum to be updated when I enter my
[hours], unless I use the key "F9".

The Dsum function works ok, is the update thing that I don't know how
to solve.

The structure is like this:
MasterForm, where there is the Dsum function
Subform01, linked to Masterform
Subform02, which is linked to subform01, with the field [hours]

The dsum funcion calculates the sum of [hours] with the same
[MasterForm ID].


TIA
Beppe

In the AfterUpdate event of Subform02 (and probably AfterDelConfirm,
too), you could execute the VBA statement

Me.Parent.Parent.Recalc
 
B

beppe005

Dirk Goldgar said:
beppe005 said:
In a Form I have a textbox with a Dsum function which calculates the
sum of [Hours] enetered in a child subform.
My problem is that I cannot get the Dsum to be updated when I enter my
[hours], unless I use the key "F9".

The Dsum function works ok, is the update thing that I don't know how
to solve.

The structure is like this:
MasterForm, where there is the Dsum function
Subform01, linked to Masterform
Subform02, which is linked to subform01, with the field [hours]

The dsum funcion calculates the sum of [hours] with the same
[MasterForm ID].


TIA
Beppe

In the AfterUpdate event of Subform02 (and probably AfterDelConfirm,
too), you could execute the VBA statement

Me.Parent.Parent.Recalc

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Thanks, it sort of work.
I userd me.parent.recalc (parent.parent gave me error)

but I have this problem now, the subform is "continuous", and after I enter
the data I am sent to the first record.
This subform has two controls/fields: [name] and [hours].

Thanks again
Beppe
 
D

Dirk Goldgar

beppe005 said:
Dirk Goldgar said:
beppe005 said:
In a Form I have a textbox with a Dsum function which calculates the
sum of [Hours] enetered in a child subform.
My problem is that I cannot get the Dsum to be updated when I enter
my [hours], unless I use the key "F9".

The Dsum function works ok, is the update thing that I don't know
how to solve.

The structure is like this:
MasterForm, where there is the Dsum function
Subform01, linked to Masterform
Subform02, which is linked to subform01, with the field [hours]

The dsum funcion calculates the sum of [hours] with the same
[MasterForm ID].


TIA
Beppe

In the AfterUpdate event of Subform02 (and probably AfterDelConfirm,
too), you could execute the VBA statement

Me.Parent.Parent.Recalc

Thanks, it sort of work.
I userd me.parent.recalc (parent.parent gave me error)

I must have misunderstood you; I thought that Subform02 was a subform
of Subform01. I guess they are both subforms of the same main form,
instead.
but I have this problem now, the subform is "continuous", and after I
enter the data I am sent to the first record.
This subform has two controls/fields: [name] and [hours].

Probably the Recalc is forcing the reevaluation of all the master/child
links. You could try one of two things.

Simplest
---------
Try recalc'ing just the specific control that has the DSum expression.
For example, if that control is named "txtTotalHours", instead of this:
Me.Parent.Recalc

use this:

Me.Parent!txtTotalHours.Recalc

I have some hope that that will work without affecting the subform
links.

More complicated
-------------------
In the subform code, remember what record you were on, and return to it
after the Recalc. For example:

Dim strName As String

strName = Me![Name]

Me.Parent.Recalc

Me.Recordset.FindFirst _
"[Name]=" & Chr(34) & strName & Chr(34)

By the way, "Name" is a bad name for a field, because most objects have
a Name property, and you don't want Access to get confused as to what
you mean.
 

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