title: LostFocus method of a text box getting executed before Form_Unload
body: <p>I am currently programming in MS Access VBA. I have a form with a textbox on it. I am executing some code on LostFocus event of the textbox. </p>
  
  <p>However, when I close the form using mouse and by clicking on close button on right-top corner of the form, with cursor in the text box, I have noticed that LostFocus event is getting executed before Form_Unload event. </p>
  
  <p>Is there a way to avoid this?</p>
  
  <p>Also, where can I find priorities of the events?? Or How are priorities decided in VBA?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>My exact application is like this.
  I have a form in MS Access which is used for accepting users' login credentials. </p>
  
  <p><img src="https://i.stack.imgur.com/ftyWu.png" alt="enter image description here"> </p>
  
  <p>I want to disble textbox for Password and Login button till a valid Username is entered. I check if the username is valid or not on onLostFocus event. Now, consider a case where this form is closed without entering anything in Username textbox. In that case, onLostFocus event gets executed before Form_Unload event. </p>
  
  <p>However, for normal operation, I require onLostFocus event because, on that event I enable Password textbox and login button. </p>
  
  <p>Could there be a different way of doing it??</p>