0

I have code where on the first try it works fine. The code ends with

710    Unload UserForm1

730    Unload UserForm2

On the first round, these trigger:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)

On the second try, my code starts to perfrom

Private Sub UserForm_Initialize() 

when it reaches Unload UserForm1.

Why is this? This causes an expected error, because Unload is supposed to end the form, not initialize it.

Tim Williams
  • 154,628
  • 8
  • 97
  • 125
Carlsberg789
  • 145
  • 1
  • 11
  • Some links that might be helpful for a better understanding of userforms: a) An outstanding overview "UserForm1.Show?" can be found at https://rubberduckvba.wordpress.com/2017/10/25/userform1-show/ b) Some related links are listed in my old post [Destroy a modeless UserForm properly](https://stackoverflow.com/questions/47357708/vba-destroy-a-modeless-userform-instance-properly) – T.M. Apr 26 '23 at 18:49
  • 1
    *"A UserForm is a class module like any other - the only difference is that it has a hidden VB_PredeclaredId attribute set to True, which makes VB create a global-scope object variable named after the class - that's how you can write UserForm1.Show without creating a new instance of the class."* cited from Mathieu Guindeau's post [Passing a variable from form to module in VBA](https://stackoverflow.com/questions/20214072/passing-variable-from-form-to-module-in-vba ) – T.M. Apr 26 '23 at 18:59

0 Answers0