by2492
04-09-2003, 10:18 PM
i have a MDIForm with some childs, and i want to check somthing everytime when child is unload.
my qustion is: there is a way to know from the MDIForm that child is unload.
thanks,
BankCop
04-09-2003, 10:39 PM
i have a MDIForm with some childs, and i want to check somthing everytime when child is unload.
my qustion is: there is a way to know from the MDIForm that child is unload.
thanks,
There's probably a better way, but -
Add a timer control to your MDI form, set it's Enabled property to False and Interval to 1.
In a standard module, create a Public Sub that can be called from the child form:
Public Sub ImClosing ()
MdiForm1.Timer1.Enabled = True
Exit Sub
In the QueryUnload or Unload event of the child form, call the ImClosing sub.
In the Timer_Timer event on the MDIform, place whatever code you want to call to do your check (I used MsgBox "I'm closing")
Private Sub Timer1_Timer()
MsgBox "I'm Closing!"
Timer1.Enabled=False
End Sub
by2492
04-09-2003, 11:24 PM
thanks, but i search for better way
VBJoe
04-09-2003, 11:35 PM
1. Declare your MDI form as Public in a module, instantiate it in Sub Main as MainForm. (Don't forget to set your Startup component to Sub Main). In Sub Main, do MainForm.Show.
2. Create a public Sub in the MDI form:
Public Sub UnloadCallback(frm as String)
Select Case frm
Case "Form1"
Debug.Print "Form1 unloaded"
'etc.
End Select
End Sub
3. In all your child forms, put the following code:
Private Sub Form_Unload(Cancel As Integer)
MainForm.UnloadCallback Me.Name
End Sub
by2492
04-09-2003, 11:59 PM
thanks, but i want to avoid coding in each child.
VBJoe
04-10-2003, 12:07 AM
Then I don't think there's an easy way to do it.
You might look into subclassing your forms and trapping the message they send when they unload.
rbulph
04-10-2003, 03:20 PM
i have a MDIForm with some childs, and i want to check somthing everytime when child is unload.
my qustion is: there is a way to know from the MDIForm that child is unload.
thanks,
You could declare a With Events Form variable ("F") in the MDIForm. The strange thing is that there doesn't need to be any code to set F to a child form - VB seems to set it to the last one to be loaded automatically. When a child form closes, F's unload event will trigger if it has focus at the time. If it does not then F's LostFocus event will occur as it briefly loses focus to the child form being closed. But you will need to play around with this further - if the last one to be loaded is closed then you will have to work out what you need to do to reset F to another child.
I can't say I would recommend doing the above - I would have thought that it had to be simplest to put something in the child form's unload event.
CornMaster
04-10-2003, 03:30 PM
Could you make use of the ActiveForm property?
rbulph
04-11-2003, 03:36 AM
Could you make use of the ActiveForm property?
Yes, probably. However as by2492 doesn't seem to want to use a timer, and so can't use this to check what the ActiveForm is, she'll have to explore when a form becomes the ActiveForm in relation to the various LostFocus and Unload Events, which may not be straightforward.
I think the quote at the bottom of your message says it all here.