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.

2
  • Some links that might be helpful for a better understanding of userforms: a) An outstanding overview "UserForm1.Show?" can be found at rubberduckvba.wordpress.com/2017/10/25/userform1-show b) Some related links are listed in my old post Destroy a modeless UserForm properly Commented Apr 26, 2023 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](stackoverflow.com/questions/20214072/… ) Commented Apr 26, 2023 at 18:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.