 |
 |

10-28-2005, 02:12 PM
|
 |
Newcomer
|
|
Join Date: Oct 2005
Posts: 14
|
|
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 
|
|

10-29-2005, 05:05 AM
|
 |
Unashamed geek
Retired Moderator * Expert *
|
|
Join Date: Jul 2003
Location: London, England
Posts: 8,988
|
|
|
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.
|
|

10-31-2005, 07:40 AM
|
 |
Newcomer
|
|
Join Date: Oct 2005
Posts: 14
|
|
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
|
|

10-31-2005, 12:47 PM
|
 |
Unashamed geek
Retired Moderator * Expert *
|
|
Join Date: Jul 2003
Location: London, England
Posts: 8,988
|
|
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
|
|

11-23-2005, 10:51 AM
|
 |
Newcomer
|
|
Join Date: Oct 2005
Posts: 14
|
|
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
|
|

11-23-2005, 01:05 PM
|
 |
Unashamed geek
Retired Moderator * Expert *
|
|
Join Date: Jul 2003
Location: London, England
Posts: 8,988
|
|
|
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.
|
|

11-23-2005, 03:05 PM
|
 |
Newcomer
|
|
Join Date: Oct 2005
Posts: 14
|
|
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 
|
|

11-25-2005, 12:15 PM
|
 |
Unashamed geek
Retired Moderator * Expert *
|
|
Join Date: Jul 2003
Location: London, England
Posts: 8,988
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|