Getting error with load/unload of UserForms??

E

Ed from AZ

My Workbook_Open() code is simply
UserForm1.Show

UserForm1 has four buttons. At this point, I'm only using CB2, which
has code
Private Sub CB2_Click()
Load UserForm2
End Sub

UserForm2_Initialize populates a ComboBox on the Form with the names
of the worksheets and then executes
Unload UserForm1
Me.Show

I select a worksheet name from the ComboBox, which executes
Private Sub ComboBox1_Change()
wkb.Worksheets(ComboBox1.Text).Visible = xlSheetVisible
wkb.Worksheets("Splash").Visible = xlSheetHidden
Unload Me
End Sub

I thought that at this point, I would be left with no code running and
looking at a worksheet. What happens, though, is that I error, and
the Debug option takes me all the way back to the UserForm1 button
code
Load UserForm2
as the bad line.

But that line was successfully executed - UserForm2 did appear and do
its thing.

How do I stop this?

Ed
 
J

Jim Rech

I'd suggest that, instead of unloading UF1, you Hide it. Then try unloading
it after you unload UF2.
 
E

Ed from AZ

Hi, Jim. I changed both form codes to simply Hide the forms instead
of Unload them. Now my workbook works fine. I tried using the
Deactivate event to unload the forms, but nothing seems to work, as
far as I can tell - I had Stop statements in the codes that were
supposed to unload the forms, but the code never got there.


This brings up a couple of questions:
(1) If the forms are hidden, is there any reason they _need_ to be
Unloaded? Will the extra memory used by them hanging in there slow
down my workbook?
(2) Is there any way to detect if a form is still open but just
hidden?

Ed
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top