Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SUM command doesn't include active field [recreated]

Status
Not open for further replies.

TomLeMes

MIS
Mar 19, 2004
96
GB
[In the process of asking me to move this thread from the 'General Coding Issues' forum to the 'Forms, Classes and Controls' forum, the original thread was deleted from the system. Here is my best effort to remember what was there originally]:

Summary
Original post: I have a 5 column grid. 2 columns of which allow users to enter values, one numeric, one text. All the cells of the grid have code on the INTERACTIVECHANGE event which calls a method of the form which totals up the values in the numeric column using:
Code:
SUM (nField) TO myvar
where nField is the field that my numeric column is bound to. The resulting myvar is then displayed on a label on the form. The idea is that the total is recalculated as the user enters the values in the grid.

The problem is that the SUM command seems to exclude the current value that the user is editing. Note that if the user is editing the text column, the SUM code is still called and in such a situation all values are included in the SUM (i.e. it works properly).

Fat Slug's reply: Try putting the call for the SUM code in the cells' VALID event?

My response: Thanks, yes that does work and is clearly better than what I have at the moment! But I was hoping to get it so that the total would re-calculate as the user typed in the values, rather than as they exit each field.

I notice that this problem only occurs if the active field is my numeric one. In other words it isn't dependent on the active record so much as the active record and field. So perhaps if I could programmatically change the active field (in the cursor, not the grid) from the numeric to the text then run the SUM code maybe it would work? Does anyone know if there is a way to do this programmatically? It would be the equivalent of browsing the data and then hitting TAB the move the active field off my numeric field. Sorry if this is a bit confusing - any ideas?
 
Seems an odd requirement that it recalculate while the user is entering the value to recalculate. That would meen updating the sum on every keystroke.

I'd put something like the following in the lostfocus of the entry textbox:

ThisForm.txtMyVar.Value = ThisForm.txtMyVar.Value + This.Value

Regards,
Jim
 
OK, thanks Jim (and FatSlug from earlier) - that seems to be the consensus so I'll leave it at that.

Thanks, Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top