Code executing twice

  • I have the below code in a UserForm to check if the ComboBox1 entry is new... or if it does exist, check if the associated records are current.
    As a side note: I used Frame1_Exit instead of ComboBox1_Exit because if a user skips the other fields in Frame1 and goes straight to the Frame2 fields, the ComboBox1_Exit is not triggered.


    The issue I'm having is;
    With the three If statements following Else, they cause the MsgBox to come up twice... once when the criteria is met, and a second when the UserForm unloads.
    If I use Me.Hide instead of Unload Me, the issue doesn't happen, but the problem with that is, when the UserForm is called again, it is as it was left and you may not get to trigger the Frame1_Exit whereby missing the required checks.


    Any thoughts on how to stop the message triggering for the second time?


  • Re: Code executing twice


    Can you attach your workbook.

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Re: Code executing twice


    The Exit event for your Frame is being called again when you try to unload the form from the original exit event. You can avoid that with a static variable like this:


    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

Participate now!

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