Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default Hiding a userform properly!

Please take a look at the code below which my workbook
is using:
'--------------------------------------------------------
Private Sub Workbook_Open()
Userform1.Show
End Sub
'-------------------------------------------------------
Private Sub UserForm_Initialize()
MsgBox "Initialize stuff here"
Userform1.Hide
MsgBox "Okay, form1 is hidden now!"
Userform1.Show
End Sub
'--------------------------------------------------------

So....obviously this code will not work. I'm guessing that
the second call to "Userform1.Show" is causing the program
to crash. I would like to temporarily hide the form and then
make it visible again. What am I doing wrong?

thanks!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Hiding a userform properly!

Not clear what the real objective is, it'd be better if you explain.

If you merely want to run the form's initialize event without showing it,

Load Userform1 '
' or anything that references the form
' initialize fires

when you want to show it (and run it's Activate event)
Userform1.show

In passing, as looks like you are trying to run the form in the workbook
open event, probably better to run it with an onTime macro, but it depends.

Regards,
Peter T


"Robert Crandal" wrote in message
...
Please take a look at the code below which my workbook
is using:
'--------------------------------------------------------
Private Sub Workbook_Open()
Userform1.Show
End Sub
'-------------------------------------------------------
Private Sub UserForm_Initialize()
MsgBox "Initialize stuff here"
Userform1.Hide
MsgBox "Okay, form1 is hidden now!"
Userform1.Show
End Sub
'--------------------------------------------------------

So....obviously this code will not work. I'm guessing that
the second call to "Userform1.Show" is causing the program
to crash. I would like to temporarily hide the form and then
make it visible again. What am I doing wrong?

thanks!




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default Hiding a userform properly!

Peter,

Okay, I'll try to explain my situation more....

I actually have 2 userforms. Userform1 is typically
displayed first because it contains buttons and other
controls. There is a button on top of Userform1 which
is designed to show Userform2.

If Userform2 is displayed, I would like to hide
Userform1. Once Userform2 gets closed out, I would
like to re-display the same Userform1 again or bring
it out of its previous hidden state.

I realize that I can leave both Userform1 and Userform2
visible at the same time, but I prefer to keep Userform1
out of view if Userform2 gets triggered. Just wondering
if this is possible.

thanks

Robert

"Peter T" <peter_t@discussions wrote in message
...
Not clear what the real objective is, it'd be better if you explain.

If you merely want to run the form's initialize event without showing it,

Load Userform1 '
' or anything that references the form
' initialize fires

when you want to show it (and run it's Activate event)
Userform1.show

In passing, as looks like you are trying to run the form in the workbook
open event, probably better to run it with an onTime macro, but it
depends.

Regards,
Peter T



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Hiding a userform properly!

Hi
The intialize code is event code - it fires when the form is loaded or
shown. The crash is probably due to the .show being inside the
initialize event code, which then fires the initialize, which does
the .show, which fires...
Don't put .Show or .Hide inside the initialize event. The initialize
simply fills your form with information that you want to see
when .Show happens.
Sounds like all you need is to put
Me.Hide
Userform2.Show

inside your event code for OKButton_Click in Userform1 (or whatever it
is called) and similarly
Me.Hide
Userform1.Show

inside your event code for OKButton_Click in Userform2
regards
Paul
On Mar 8, 10:02*am, "Robert Crandal" wrote:
Peter,

Okay, I'll try to explain my situation more....

I actually have 2 userforms. * *Userform1 is typically
displayed first because it contains buttons and other
controls. *There is a button on top of Userform1 which
is designed to show Userform2.

If Userform2 is displayed, I would like to hide
Userform1. * Once Userform2 gets closed out, I would
like to re-display the same Userform1 again or bring
it out of its previous hidden state.

I realize that I can leave both Userform1 and Userform2
visible at the same time, but I prefer to keep Userform1
out of view if Userform2 gets triggered. * Just wondering
if this is possible.

thanks

Robert

"Peter T" <peter_t@discussions wrote in message

...



Not clear what the real objective is, it'd be better if you explain.


If you merely want to run the form's initialize event without showing it,


Load Userform1 '
' or anything that references the form
' initialize fires


when you want to show it (and run it's Activate event)
Userform1.show


In passing, as looks like you are trying to run the form in the workbook
open event, probably better to run it with an onTime macro, but it
depends.


Regards,
Peter T- Hide quoted text -


- Show quoted text -


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Hiding a userform properly!

Paul has already covered most of what I would have said.

Whilst I follow what you describe below, I don't follow it in relation to
what you originally posted at all, no way to slot in stuff about hiding the
form and showing some other within the Initialize event. Is this two
different topics perhaps.

Regards,
Peter T

"Robert Crandal" wrote in message
...
Peter,

Okay, I'll try to explain my situation more....

I actually have 2 userforms. Userform1 is typically
displayed first because it contains buttons and other
controls. There is a button on top of Userform1 which
is designed to show Userform2.

If Userform2 is displayed, I would like to hide
Userform1. Once Userform2 gets closed out, I would
like to re-display the same Userform1 again or bring
it out of its previous hidden state.

I realize that I can leave both Userform1 and Userform2
visible at the same time, but I prefer to keep Userform1
out of view if Userform2 gets triggered. Just wondering
if this is possible.

thanks

Robert

"Peter T" <peter_t@discussions wrote in message
...
Not clear what the real objective is, it'd be better if you explain.

If you merely want to run the form's initialize event without showing it,

Load Userform1 '
' or anything that references the form
' initialize fires

when you want to show it (and run it's Activate event)
Userform1.show

In passing, as looks like you are trying to run the form in the workbook
open event, probably better to run it with an onTime macro, but it
depends.

Regards,
Peter T





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
UserForm Labels not Showing Properly RyanH Excel Programming 3 December 15th 09 10:57 PM
UserForm Not Hiding Mike H. Excel Programming 1 November 28th 07 09:32 PM
Dynamically Hiding portions of a UserForm fly_fish_boy Excel Programming 0 March 14th 06 05:56 PM
UserForm from VBA macro is not getting properly unloaded Robin Hammond[_2_] Excel Programming 2 December 8th 05 09:45 AM
UserForm not hiding Tony Bender Excel Programming 4 October 9th 03 08:42 PM


All times are GMT +1. The time now is 12:03 AM.

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"