Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Excel > Form freezing when it's hiding


Reply
 
Thread Tools Display Modes
  #1  
Old 10-28-2005, 02:12 PM
AndyDandy's Avatar
AndyDandy AndyDandy is offline
Newcomer
 
Join Date: Oct 2005
Posts: 14
Question Form freezing when it's hiding


I have one form hiding while another displays.
When this form closes, it show the first caller form

<vb>
Sub UserForm1.Button_Click()
UserForm2.Show
Me.hide
End Sub

Sub UserForm_QueryClose(yada, yada)
Me.Hide
UserForm1.Show
End Sub
</vb>

This works the first time, but subsequent attempts to close UserForm2 freezes it - UserForm1 won't appear and UserForm2 won't hide.
(I'm using the [X] button)

This is under Excel 2003

Andy
Reply With Quote
  #2  
Old 10-29-2005, 05:05 AM
herilane's Avatar
herilane herilane is offline
Unashamed geek

Retired Moderator
* Expert *
 
Join Date: Jul 2003
Location: London, England
Posts: 8,988
Default

Your current code doesn't even run once for me (even disregarding the yada, yada). Can you post the actual code you are using?

Userforms can be shown modelessly or modally. Modal means that all other code will stop until the form has been closed.
Modal is the default method, so if you call Userform2.Show without any arguments, the next line (Me.hide) won't actually run until Userform2 has been closed.
To show a form modelessly, use .Show vbModeless.
Reply With Quote
  #3  
Old 10-31-2005, 07:40 AM
AndyDandy's Avatar
AndyDandy AndyDandy is offline
Newcomer
 
Join Date: Oct 2005
Posts: 14
Question RE: Forms freezing

Ok, here's my code

frmMain:
Code:
' frmMain Training button - displays Training menu screen Private Sub cmdTraining_Click() Me.Hide frmTraining.Show End Sub

frmTraining
Code:
' frmTraining Close event Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) Me.Hide frmMain.Show End Sub

when you start on frmMain and call frmTraining it appears.
closing frmTraining should return to frmMain and it does.
if you call frmTraining again, frmTraining doesn't close
both forms are in memory now so .Show should work
Reply With Quote
  #4  
Old 10-31-2005, 12:47 PM
herilane's Avatar
herilane herilane is offline
Unashamed geek

Retired Moderator
* Expert *
 
Join Date: Jul 2003
Location: London, England
Posts: 8,988
Default

It's still due to the modal / modeless issue. When you first close frmTraining, you're showing frmMain again. You're showing it modally, which means that the QueryClose event can't continue until frmMain has been hidden. So the QueryClose event never finishes. I suspect that this unfinished event procedure is blocking all other events in frmTraining (when you show frmTraining again).

Here's how you can do this instead:

frmMain:
Code:
' frmMain Training button - displays Training menu screen Private Sub cmdTraining_Click() Me.Hide frmTraining.Show [b]Me.Show 'added[/b] End Sub
frmTraining
Code:
' frmTraining Close event Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) Me.Hide [b]'frmMain.Show removed[/b] End Sub
Reply With Quote
  #5  
Old 11-23-2005, 10:51 AM
AndyDandy's Avatar
AndyDandy AndyDandy is offline
Newcomer
 
Join Date: Oct 2005
Posts: 14
Default

Thx. That worked.
Is there a method to re-init the form every time I show it?

The forms re-init when I use Unload Me rather than Me.Hide

Would this code work the same way?
Code:
Unload Me frmMain.Show Load Me

It doesn't feel right where a form loads itself
Reply With Quote
  #6  
Old 11-23-2005, 01:05 PM
herilane's Avatar
herilane herilane is offline
Unashamed geek

Retired Moderator
* Expert *
 
Join Date: Jul 2003
Location: London, England
Posts: 8,988
Default

No, a form can't load itself - when you unload the form, it's gone, dead, erased, and it cannot run any code.

Which form do you want to reinitialize? The Training form? In that case, just let the main form unload / load it as needed.
Reply With Quote
  #7  
Old 11-23-2005, 03:05 PM
AndyDandy's Avatar
AndyDandy AndyDandy is offline
Newcomer
 
Join Date: Oct 2005
Posts: 14
Unhappy

Oh
Umm...This is game plan I'm currently operating under:
-global Module invokes New instances of each form
-Main form Loads the appropriate form on button click
-Each subform Unloads itself when the user click a custom back button.
-Eventually the user would end up back @ Main

Main grants life to forms(Load) and each subform suicides out (Unload Me)
sounds simple except for the automation error stating frmMain cannot Load a form that killed itself (i.e. can't do it's job)


This is what we are ultimately pursuing - a data storage application done in Excel2003 thru VBA

i just need a way to flip back & forth through forms
Reply With Quote
  #8  
Old 11-25-2005, 12:15 PM
herilane's Avatar
herilane herilane is offline
Unashamed geek

Retired Moderator
* Expert *
 
Join Date: Jul 2003
Location: London, England
Posts: 8,988
Default

It's not that hard...
Attached Files
File Type: zip Back and forward.zip (11.8 KB, 7 views)
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->