Calculation on exiting TextBox

gsandy

Registered User.
Local time
Today, 20:27
Joined
May 4, 2014
Messages
104
I have a data entry form (frmHourEnter) where hours are entered a TextBox (Hours_Worked). The next tabbed TestBox (txtHrsTotal) gives a running total of hours – the code in Control Source being:
Code:
  =DSum("Hours_Worked","tblHourEnter","Staff_ID =" & [Forms]![frmHourEnter]![Staff_ID] & " AND Week_No=" & [Forms]![frmHourEnter]![txtDateCalc])
But this only gives the running total up to the previous entry.
How can I get the running total to include the last entry into “Hours_Worked” i.e on exiting this textbox)?

Thanks Sandy
 
I have a data entry form (frmHourEnter) where hours are entered a TextBox (Hours_Worked). The next tabbed TestBox (txtHrsTotal) gives a running total of hours – the code in Control Source being:
Code:
  =DSum("Hours_Worked","tblHourEnter","Staff_ID =" & [Forms]![frmHourEnter]![Staff_ID] & " AND Week_No=" & [Forms]![frmHourEnter]![txtDateCalc])
But this only gives the running total up to the previous entry.
How can I get the running total to include the last entry into “Hours_Worked” i.e on exiting this textbox)?

Thanks Sandy

Add the value in the textbox to the Dsum calculation?
Save the record, then do the Dsum?
 
So for option one I would add - "Hours_Worked" + DSum(etc) into the Control Source?
For option two would I add code to save record on exiting Hours_Worked" textbox?
 
Yes.
The first option is assuming that would be the value saved, you have just not saved it yet.
The second option is forcing you to save it, to get your desired result.

This is assuming that you are using bound controls for the second option?

http://www.techrepublic.com/blog/mi...save-the-current-record-in-access-using-code/

How your form works will determine which is the best method of those I have offered. There may well be other ways, there normally is with computers :-)
 
Thanks for the link. Where do I put the "If Me.Dirty etc" code? I am much more familiar with Excel!
 
Thanks for the link. Where do I put the "If Me.Dirty etc" code? I am much more familiar with Excel!

I believe you would just put it before you do your Dsum, That way the record will be updated correctly.
I think this is the best way to go, as what happens if a user reduces the value?, you would want the record save before doing the Dsum again.
 

Users who are viewing this thread

Back
Top Bottom