Reputation: 19737
I have this code in one command button in UserForm2:
Private Sub CButton1_Click()
UserForm1.Show
Me.Hide
End Sub
Now, Userform1
is shown.
Then I have another code in one command button in Userform1:
Private Sub CButton2_Click()
UserForm2.Show
Unload Me
End Sub
This throws up a:
Runtime Error: Form already displayed; can't show modally
How do I do this properly?
How do I go back to the previous Userform
after hiding or unloading it?
Upvotes: 2
Views: 12146
Reputation: 456
I think the problem is the order of the statements. I found out by using the debugger that when I had the Show statements before the Hide or Unload, these last are not executed.
Try this
' on UserForm2
Private Sub CommandButton1_Click()
Me.Hide
UserForm1.Show
End Sub
' on UserForm1
Private Sub CommandButton1_Click()
Me.Hide
UserForm2.Show
End Sub
Upvotes: 6
Reputation: 493
Change to this:
Private Sub CButton1_Click()
Me.Hide
UserForm1.Show
Unload Me
End Sub
Private Sub CButton2_Click()
Me.Hide
UserForm2.Show
Unload Me
End Sub
Upvotes: 3