Totaling a column of numbers as a user enters values

This seems like such a basic newbie question, but it is one that has always eluded me.

OK say I have a bunch of editable number fields

Num1

Num2

Num3

and below those a computed total field.

I know the forumla to total up the numbers, that is not the problem. What is happening because of the way Notes processes computed fields is the total field is not updated until the editable field after the total field is entered.

Other than placing the total field above all of the other fields or having each of the number fields force a document refresh, how can I get the total field to refresh as each number is entered?

Subject: Totaling a column of numbers as a user enters values

Bruce,

In this situation, I throw these 2 lines in the ‘exiting’ or ‘onchange’ event of each number field:

Dim workspace As New NotesUIWorkspace

Call workspace.CurrentDocument.Refresh

It does force a document refresh, which could be expensive depending on your other fields. But if you don’t have to go back to the server for anything, then the refresh happens in the client and is quite fast.

By the way, I’ve been using your ‘sequential number’ code for years. Thanks for sharing it.

Subject: RE: Totaling a column of numbers as a user enters values

Thanks as I mentioned in my post, I did not want to refresh the whole form because then it sets off the validation formulas.

Subject: RE: Totaling a column of numbers as a user enters values

Not if you use @IsDocBeingRecalculated in your validation formulas, it doesn’t. (That’s one of Andre’s known pet peeves.)

Subject: RE: Totaling a column of numbers as a user enters values

Thanks Stan,

I was not aware of that function.

Subject: RE: Totaling a column of numbers as a user enters values

As Stan mentioned, @IsDocBeingRecalculated, or, my personal preference, @IsDocBeingSaved will make sure the validation formulas don’t fire when the total is updated.

Subject: RE: Totaling a column of numbers as a user enters values

There’s one niggle with @IsDocBeingSaved, and that’s that it will report a false pass if you use @IsValid in an action. In R5 it was the only way, but @IsDocBeingRecalculated will let you properly check validations without saving.

Subject: RE: Totaling a column of numbers as a user enters values

Thanks, Stan. I haven’t run into that problem, but I’ll keep an eye out for it. I find the designer help entry on @IsDocBeingRecalculated pretty obtuse (does recalculate = refresh? what about refreshhideformulas? and is there an automatic recalc/refresh when you save? wouldn’t you always want to recalc before a save?). @IsDocBeingSaved feels so simple - either you are saving or not, and my goal is usually to prevent my validation formulas from firing until the user is ready to save. I use it a lot.

Subject: RE: Totaling a column of numbers as a user enters values

That’s assuming you’re using the Automatically refresh fields form option, which I rarely use. Instead, you might use the Onblur or Onchange field events to either refresh the whole form, or execute some code to calculate and update the total without refreshing anything.