L
Luke
I have a UserForm1 with a ListBox1 in it. When I click on an entry from
ListBox1, UserForm2 appears. UserForm2 has the equivalent of "OK" and
"Cancel" buttons on it (among other things).
I had been so busy testing other features that it never occurred to me to
test the Cancel button until now. What I found is that, when Cancel is
clicked, UserForm2 unloads (as it should) and then immediately reappears.
The "UserForm2.Show" line of code is the first line in the ListBox1_Click()
sub. I assumed that, since an entry was still selected in ListBox1, it was
counting that as a click and re-running the ListBox1_Click() sub.
To fix this, I added this line of code to the CommandButton2_Click() sub
(the Cancel button): UserForm1.ListBox1.ListIndex = 0. That line of code
came after the "Unload UserForm2" line in the same sub. However, I then got
a Run-time error 400: Form already displayed; can't show modally. The
highlighted line of code was the UserForm2.Show line in the ListBox1_Click()
sub.
How can I click the Cancel button on UserForm2, unload UserForm2, and have
ListBox1 (in UserForm1) sitting there ready for me to choose a new entry?
ListBox1, UserForm2 appears. UserForm2 has the equivalent of "OK" and
"Cancel" buttons on it (among other things).
I had been so busy testing other features that it never occurred to me to
test the Cancel button until now. What I found is that, when Cancel is
clicked, UserForm2 unloads (as it should) and then immediately reappears.
The "UserForm2.Show" line of code is the first line in the ListBox1_Click()
sub. I assumed that, since an entry was still selected in ListBox1, it was
counting that as a click and re-running the ListBox1_Click() sub.
To fix this, I added this line of code to the CommandButton2_Click() sub
(the Cancel button): UserForm1.ListBox1.ListIndex = 0. That line of code
came after the "Unload UserForm2" line in the same sub. However, I then got
a Run-time error 400: Form already displayed; can't show modally. The
highlighted line of code was the UserForm2.Show line in the ListBox1_Click()
sub.
How can I click the Cancel button on UserForm2, unload UserForm2, and have
ListBox1 (in UserForm1) sitting there ready for me to choose a new entry?