Search code examples
excelvbauserform

Stop in Close and Open userforms _VBA


I created two forms. Pressing the button 1 opens the form number 2. By closing the form number 2, the form number 1 is displayed. But this action is only done once and it stops for the second time and almost does not work. Where does the code have a problem?

code Userform1:

Private Sub ShowUserform2_Click()
  UserForm1.Hide
  Unload UserForm1
  UserForm2.Show
End Sub

Code userform2:

Private Sub UserForm_Terminate()
  UserForm2.Hide
  Unload UserForm2
  UserForm1.Show
End Sub

Solution

  • Skip the formName.Hide lines. They are unnecessary.

    After the Unload formName statements add:

    Set formName = Nothing
    

    Also, make the otherForm.Show line precede the above two lines.