Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Global variable destroyed when form closed

I have an Excel application with some forms and some global variables.

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.

There is no collision of variable names, and I don't have any macros in
the form so I can't understand what happens to my global variables.

My other forms does not have this problem.

I would very much appreciate any help in this matter!

Best Regards
Fredrik

  #2   Report Post  
Posted to microsoft.public.excel.programming
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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Global variable destroyed when form closed

Fredrik,
Sounds like you have declared those variables on the form.
Put them in a module and they will remain until the workbook is closed.

NickHK

wrote in message
oups.com...
I have an Excel application with some forms and some global variables.

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.

There is no collision of variable names, and I don't have any macros in
the form so I can't understand what happens to my global variables.

My other forms does not have this problem.

I would very much appreciate any help in this matter!

Best Regards
Fredrik



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Global variable dhstein Excel Discussion (Misc queries) 2 October 30th 09 01:03 PM
Setting form caption based on global variable JNW Excel Programming 10 July 20th 06 10:47 PM
Global Variable Francis Brown Excel Programming 4 November 27th 05 06:38 PM
Global Variable Patrick Simonds Excel Programming 8 October 6th 05 12:39 AM
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? Daniel Excel Worksheet Functions 1 July 9th 05 03:05 AM


All times are GMT +1. The time now is 11:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"