onChange called twice

I have a form with 5 rich text fields on it. Each has some code in the onChange event to calculate the number of characters entered in the field. The onChange code calls “uiDoc.Refresh True” so that the rich text fields are included in the refresh and therefore available to be counted (without having to save the document). This works fine, except for one small problem.

If you enter text in 1 of the fields and tab to the next one, the first field’s onChange is executed. Enter some text in the second field and then tab back to (or click in) the first field, and the first field’s onChange event is executed again, and then the second field’s onChange event is called. I have stepped through the code and it seems that the second field’s onChange even is called first, but when the code calls the uiDoc.Refresh True line, this triggers the onChange event of the first field, even though the first field has not been changed by the user.

It doesn’t matter which 2 fields are being used, if all 5 fields have text in them, the onchange event for the previously edited field is also triggered when you exit out of the current one.

This wouldn’t be a problem except the onChange event is being used to display a warning about field contents and should only be dispayed once, unless the field is edited - this is why the onChange event was used.

Does anyone know why refreshing the uidocument causes an invisible change to the previous rich text field, triggering it’s own onchange event? This problem goes away if the fields are all just plain text.

Thanks for your help.

Andy

**** I just noticed that this is happening for normal text fields as well. If you have a uidoc.Refresh call in the onchange event of either text or rich text fields, it causes the onchange event of the previously edited field to be called as well.

Subject: onChange called twice

My first thought is that it sounds like a bug (the way you describe it), yet I would more be inclined to bet that it is more likely your code. Any chance your code is moving the cursor between fields or changing any field values? I have experienced similar issues with the Exiting event. One event would move the cursor here which triggerred another event which moved the cursor back, which triggered the first event again, which …It might help to post example code.