On Form Close

Lanc1988

Contributor
Joined
Nov 27, 2003
Messages
508
On my main form i want it do do something when one of my other forms closes, my main form is called frmMain and my other form is called frmLookup

so is there a code that i can put on my main form to say something like when frmlookup closes do the following and it would do what i need it to do.
 
How is frmLookup created?

If modally via ShowDialog then you could dimension a Public Shared variable called Response As DialogResult in frmLookup's declaration section. When frmLookup closes set Response to DialogResult.Ok. Then from frmMain use:

Dim newLookup as New frmLookup
newLookup.ShowDialog
If newLookup.Response = DialogResult.Ok Then
'do your stuff here
End If

If you create frmLookup with .Show then you'll need to setup a delegate in frmLookup like
...in the declaration section of frmLookup:
Event ClosingForm()

When you close frmLookup call the delegate by raising the event:
Private Sub frmLookup_Closing(by Val........) Handles MyBase.Close
RaiseEvent ClosingForm()
End Sub

Then in frmMain finish the process with a sub to handle the delegate:
Private Sub frmLookupClosed Handles frmLookup.ClosingForm()
'do your stuff here
End Sub

I hope that gives you a few options to start with.
 
Back
Top