PDA

View Full Version : Solved: Excel Form



joms
12-13-2010, 09:37 PM
Hi guys, need your help stuck with this.

I'm using excel 2007.

I had two forms, userform1 and userform2.
I had a button on userform1 to display userform2.

When i click on the button on userform1 to display userform2, it works fine.

But when i close userform2. Then click again on userform1 button to display userform2.
Userform2 will display, but the form will just display but i cannot close the form. It's like the form just freeze, i need to press ctrl break to exit.


Codes for displaying the two forms:
useform1 button:

userform2.show
Unload Me



code on userform2:
userform2_terminate

Unload me
userform1.show


why it's behaving like this, it's just hide and show of the forms. any ideas is greatly appreciated. Thanks. :think:

macropod
12-13-2010, 10:32 PM
Hi joms,

Try:
Me.Hide
Userform2.Show
and
Me.Hide
Userform1.Show

joms
12-14-2010, 06:57 PM
hi macropod, had tried your suggestion but still hang. any ideas?

macropod
12-15-2010, 12:35 AM
Hi joms,

Perhaps you could post an attached workbook containing the basic userforms and their code. It's hard to diagnose such issues with only the information you've given so far.

joms
12-15-2010, 09:21 PM
hi macropod, thanks for your reply.

i just found out that what causes the hang, whenever there's a code on terminate event or activate event on form2.

so what i did, i just disable the x button on the form and force the user to use the exit button on the form. and it works fine.

but still puzzled why cannot put a code on the terminate and activate event on form2. any ideas? or have you encountered same problem before?

thanks, :)

macropod
12-16-2010, 03:59 AM
Hi joms,

When you simply close a form, without code to trap the closure, all code execution related to that form simply stops.

With the userform2 code you originally posted, you also unloaded the form (which terminates its code execution) before trying to reload userform1. Again, the result is that everything simply comes to a stop.

joms
12-16-2010, 07:33 PM
thanks macropod, for the enlightenment. Cheers :)