Object reference not set to an instance of an object

I have a view form which loads a instance form, here is the code. The problem is the user can close the main form. Is there anything I can check before closing the main form to see if any new forms have been spawned from it.

       Dim frm As New UserForm
                AddHandler frm.Closed, AddressOf InstanceFormClosed
                Me.Cursor = Cursors.Default
                frm.Show()
rocky050371Asked:
Who is Participating?
 
Joel CoehoornConnect With a Mentor Director of Information TechnologyCommented:
Try doing it this way:

Dim frm As New UserForm(Me)
AddHandler frm.Closed, AddressOf InstanceFormClosed
Me.Cursor = Cursors.Default
frm.Show()

Then you can look at Me.OwnedForms to see a list of forms that were opened with this code.
0
 
mdouganCommented:
There is a windows API called enumChildWindows that you might be able to call... I used it in an example to enumerate all the controls on a given form, but it might also work for windows spawned from another window... worth a try.  This example code is in VB 6, but you can probably cut and paste into .NET

https://filedb.experts-exchange.com/incoming/ee-stuff/6681-UserControlsSample.zip

0
All Courses

From novice to tech pro — start learning today.