View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jan Karel Pieterse Jan Karel Pieterse is offline
external usenet poster
 
Posts: 535
Default Global variable destroyed when form closed

Hi,

For one of the forms I have a problem. If I close the form by pressing
the "x" in the right corner, all my global variables get cleared. If I
close it by using userform.hide then it's no problems.


Clicking the X effectively unloads the form from memory. You should
include this event in the form's code:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then
'Hide the form
Me.Hide
'Prevent unloading
Cancel = True
Else
'Do other stuff if some other action closes the form
End If
End Sub

Regards,

Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com
Member of:
Professional Office Developer Association
www.proofficedev.com