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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HOW TO CLOSE ALL FORMS IN MDIform 1

Status
Not open for further replies.

Judai

Programmer
Oct 23, 2002
42
0
0
IL
Hey U all,

How can I close all the forms I have running within an MDIForm.

Is there a definition to an MDIChild form object?

Thanks,
J.
 
You could try the form's MDIChild property per VBHelp

Dim f As Form
For Each f In Forms
If f.MDIChild = True Then
Unload Me
End If
Next

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
of course Unload Me should read Unload f.
apologies for typo
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
johnwm,

Still the same error message,

Please notice this is a Func().
 
Ban nen dung code sau:

Private Sub mnuExit_Click()
Dim iFormCount As Integer

For iFormCount = Forms.Count - 1 To 0 Step -1
Unload Forms(iFormCount)
Next iFormCount
End Sub


Thanh Binh - Viet Nam
 
Judai,
What do you mean:
Still the same error message,

Please notice this is a Func().


You haven't mentioned error message or code before!
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
johnwm,

Well, this is the full description of the problem:
Code:
Function Activate_Cmd_Menu(Group, Index)
===============================
Dim iFormCount As Integer

For iFormCount = Forms.Count - 1 To 0 Step -1
    Unload Forms(iFormCount)
Next iFormCount
===============================
Select Case (Group)
    Case 0
        Select Case (Index)
            Case 0
                frmSupplier.Show
            Case 1
                frmReceipts.Show
        End Select
    Case 1
End Select
End Function

I am trying 2 find out if there R any forms open inside the parent MDI.

So I tried thbinh's code, that replaced your code, which looked like this:

Code:
Function Activate_Cmd_Menu(Group, Index)
===============================
Dim f As Form

For Each f In Forms
    If f.MDIChild = True Then
Unload f
End If
Next
===============================
Select Case (Group)
    Case 0
        Select Case (Index)
            Case 0
                frmSupplier.Show
            Case 1
                frmReceipts.Show
        End Select
    Case 1
End Select
End Function

Well, they both don't work.

I guess because yours treats an MDIChild from its code, & thbinh's, well, I don't know.

Do U guys have any other solution, or maybe the information I gave U now gives you a better idea of what the problem is??!!

Thanks alot 4 the time & effort.

Jud.
 
You've written this as a Function, but it appears to be a Sub (i.e. returns no value)
How are you calling the function?

What exactly do you mean:
Well, they both don't work.

Are the forms not closing?
Is there an error message?
If so, what and where?
Or is the new form not opening?

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 


Just one comments:

Where are you calling the function from, and in which module is the function located?
[/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
This is more or less how it looks:
Code:
Dim recept as Integer
Public Sub cmd_Options_Click(Index As Integer)
recept = Activate_Cmd_Menu(A_group, Index)
End Sub
==============================================
Function Activate_Cmd_Menu(Group, Index)

Dim f As Form
For Each f In Forms
    If f.MDIChild = True Then
Unload f
End If
Next

Select Case (Group)
    Case 0
        Select Case (Index)
            Case 0
                frmSupplier.Show
            Case 1
                frmReceipts.Show
        End Select
    Case 1
End Select
End Function
==============================================
For each different button press, a different form is open within the MDIForm.
The function checks which button is pressed & displays the apropriate form.
They are both in the same modul.
I have even tried to make the function public, this does nothing.
The error message displayed is:

Run-time error '380':
Invalid property value

What do you guys think??

Thank you again.
J.

 
Use the folowing code.
This is because one of the forms is the MdiForm, which hasn't a MdiChild property.

Dim f As Form
For Each f In Forms
If Not TypeOf f Is MDIForm Then If f.MDIChild = True Then Unload f
Next


Carlos Paiva
 
Hey guys,

Carlos has the right answer.

Thank U all 4 the time & patients.

Special thanks 2 Carlos...!!!
 
Judai,

Looking back at your profile I guess you haven't discovered the 'Mark this post as helpful/expert'

Carlos seems to have come up with the solution that we all struggled for, so I will give him a star anyway
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top