Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unload mdichild if it is loaded 1

Status
Not open for further replies.

biddingbong

IS-IT--Management
Sep 10, 2004
67
MU
Hello everybody, Ive got an MDI form and when endinf the app I want to unload the mdichild first and then END. But the problem is that when there is no mdichild loaded I get an error.
I tried this code:
'Me is the MDI
If Me.ActiveForm <> Nothing Then Unload Me.ActiveForm

But I still get errors.
 
Try....
Code:
Dim i As Integer

For i = 0 to Forms.Count
    If Forms(i).MDIChild = True then
        Unload Forms(i)
    End If
Next i

Casper

There is room for all of gods creatures, "Right Beside the Mashed Potatoes".
 
You should not be doing an END but unloading the MDIForm then when you unload the MDIform it will automatically unload all the child forms.

Also the code previously provided will not work - you will get an error as MDIChild is not a valid property for an MDIform. Forms.count is not a vaild subscript (s/b forms.count-1), also as you remove forms the index changes and the upper bound goes down giving a subscript out of range error. My version -
Code:
Dim f As Form

For Each f In Forms
    If f.Name <> Forms(0).Name Then  'forms(0) is the MDIForm
     Unload f
    End If
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top