BeforeUpdate Event Fires Multiple Times

  • Hey,


    I wrote some code to validate an inputfield. I want to keep the focus on this field until a correct (numeric) value is inputed. Therefore I use teh beforeUpdate event instead of the afterUpdate event. Some strange things happen (see code below):


    1. When I press enter after putting some non-numeric data in the inpBedrag2 field the msgbox is displayed three times in a row. This doesn't happen when the field loses focus by clicking another field (-> msgbox only displays once = correct behaviour)
    2. What's really driving me nuts is the fact that the (more or lesse the same sub) works perfectly.


    What am I doing wrong? I'm not getting it. Probably I'm doing something very stupid ... but I can't figure it out myself.



    Thanks in advance,
    Jan Coonen

  • Re: Beforeupdate Triggers Multiple Times


    The event fires itself since it updates the value within it.
    Explore Application.Enableevents


    p45cal

  • Re: Beforeupdate Triggers Multiple Times


    Where is this input field located?


    If it's on a userform then turning off events ain't going to make a difference.


    If it is on a userform and you want to validate then I would suggest you use another event, perhaps Exit.

  • Re: Beforeupdate Triggers Multiple Times


    Those fields are indeed located on a userform.


    The strange thing is ... everything works smoothly with inpBedrag_BeforeUpdate but strange things happen with inpBedrag2_BeforeUpdate (almost the same code) ...


    The properties for the fields are identical except for the name off course.


    Initially I used the afterupdate event but this changes the focus to the next field in the tabindex order.

  • Re: Beforeupdate Triggers Multiple Times


    Quote

    ... but this changes the focus to the next field in the tabindex order

    You can set the focus back in the AfterUpdate event.

    [SIZE=1]Entia non sunt multiplicanda sine necessitate.[/SIZE]

  • Re: Beforeupdate Triggers Multiple Times


    You can use a Module level Boolean Variable to stop the event firing. Although, I would step through your code and discover what exactly is causing it to fire.

  • Re: BeforeUpdate Event Fires Multiple Times


    Quote

    You can set the focus back in the AfterUpdate event.


    How is this done? I tried it before by setting myFormControlName.setfocus in the afterupdate event, but it didn't work. Therefore I started exploring the beforeUpdate event.

  • Re: BeforeUpdate Event Fires Multiple Times


    Hey,


    I just tried to fix it with the exit event, but:
    1. the event isn't triggerd when your press the ENTER-key
    2. the same error occurs


    I'll add an example workbook as an attachement. Feel free to examine it. Every kind of "critisism" is welcome, but ... remeber I'm rather new to this (but I've got some programming experience in other languages).


    The form is written in Dutch, but I think it's obvious what the goal is. It's a very simple program written to help me develop some excel skills ... but now I haven' t been able to find out what's going wrong ... it's really frustrating me ...


    Thanks in advance to all who want to spend some time finding out what's going wrong.


    Bye,
    Jan.

  • Re: BeforeUpdate Event Fires Multiple Times


    Thanks Reafidy. I'll think of it in the future.


    Do you do .ZIP files Norie?[hr]*[/hr] Auto Merged Post;[dl]*[/dl]Hey,


    I finally found what I was doing wrong! To make my form look a little more attractive I've grouped my control into frames.


    I've stopped using the beforeUpdate-event and I use the exit-event as was suggested by reafidy. But I encouterd another problem. The exit-event wasn't triggerd (on the last field in an frame) by pressing the ENTER-key. I changed the cycle-propery to fmCycleCurrentForm and everything works fine. Except for one thing ... when I exit the form by clicking the close (X) with the focus on a field with some validation-code in the exit-event the validation-messages in the exit-event are still shown after the form is closed. But ... I'll start a new thread for this problem.


    Greets and thanks for all the suggestions.
    Jan.[hr]*[/hr] Auto Merged Post;[dl]*[/dl]Hey,


    I finally found what I was doing wrong! To make my form look a little more attractive I've grouped my control into frames.


    I've stopped using the beforeUpdate-event and I use the exit-event as was suggested by reafidy. But I encouterd another problem. The exit-event wasn't triggerd (on the last field in an frame) by pressing the ENTER-key. I changed the cycle-propery to fmCycleCurrentForm and everything works fine. Except for one thing ... when I exit the form by clicking the close (X) with the focus on a field with some validation-code in the exit-event the validation-messages in the exit-event are still shown after the form is closed. But ... I'll start a new thread for this problem.


    Greets and thanks for all the suggestions.
    Jan.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!