Unloading userforms

O

Oggy

Hi

I have wrote a few macros to open up a userform and when finished,
with a comand boutton open a different userform. I keep getting an
error 28 after running them for a little while. I have recreated the
problem by writing the following code to establish the loading of
userforms is the problem. has anyone got any suggestions on how i can
resolve the problem.

Thanks in advance

Addy




Private Sub CommandButton1_Click()
Unload userform2
Set userform2 = Nothing
Run "a"
End Sub



Sub a()
userform1.Show
Unload userform1
Set userform1 = Nothing
End Sub


Private Sub CommandButton1_Click()
Unload userform1
Set userform1 = Nothing
Run "b"
End Sub

Sub b()
userform2.Show
Unload userform2
Set userform2 = Nothing
End Sub
 
R

RB Smissaert

It looks you have to keep better track of which forms are loaded or not or
avoid the error by doing On Error Resume Next.

RBS
 
M

merjet

Each procedure goes with which UserForm?

Run "a" doesn't work for me. 'Call a' or 'a' (w/o the quotes) does.

You don't have to Unload a Userform. You can use Hide if you may want
to show it again.

It might help to say what you want to do.

Merjet
 
O

Oggy

Each procedure goes with which UserForm?

Run "a" doesn't work for me. 'Call a' or 'a' (w/o the quotes) does.

You don't have to Unload a Userform. You can use Hide if you may want
to show it again.

It might help to say what you want to do.

Merjet

Thanks

I have written an estimating system where the user puts the infomation
into a spreadsheet via a userform. To make it easier for the user i
have 1 userform to enter the parts details, i userform to enter the
materials details and finally 1 userform for the labour details, this
then returns to a menu which is also a userform. My problem is that i
can only enter about 30 parts etc... then it will error 28 memory
stack is full. i have found the problem is the loading/unloding
userforms.

Addy
 
P

Peter Grebenik

If you examine the call stack (go into debug mode then use Ctrl-L) you
will see that the problem is not with loading and unloading the forms,
but because your "a" and "b" procedures get called recursively and
never terminate.

Peter Grebenik
 
O

Oggy

If you examine the call stack (go into debug mode then use Ctrl-L) you
will see that the problem is not with loading and unloading the forms,
but because your "a" and "b" procedures get called recursively and
never terminate.

Peter Grebenik

Hi

I have taken your advise and have now not used the a & b procedures
and now switch from one userform to another and i have found that when
i switch they do not unload from the memory stack and after a while i
still get the error 28.

Is there a way of stopping the buildup in the memory or am i asking to
much?

thanks
 
P

Peter Grebenik

Without seeing the code, I don't know.

Have you thought of using a multipage control on your userform to get
around the problem of constantly loading and unloading forms?

Peter Grebenik
 

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

Top