[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:
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?
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
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?