I suppose there are many programs of the form, I can determine how much the order form is opened and the name of the form is not open? Who can share me with example, thanks
Printable View
I suppose there are many programs of the form, I can determine how much the order form is opened and the name of the form is not open? Who can share me with example, thanks
Code:Private Sub Command3_Click()
Dim NumberOfForms As Integer 'Variable to hold number of open forms
NumberOfForms = Forms.Count 'Count all open forms
MsgBox NumberOfForms 'Display variable
Dim intCounter As Integer
For Each Form In Forms 'Loop through Forms collection
MsgBox Forms(intCounter).Name 'Display each open form's name
intCounter = intCounter + 1
Next
End Sub
I don't understand your last question. Mind rephrasing it a bit, please
1. Have i want to order of forms openning ?
2. I want to close all form openning but not and warning error
For Each frm In Forms
If frm.Name <> Me.Name Then
If frm.MDIChild = True Then
MDIMainForm.RemoveChild frm.Name ' Error here
End If
End If
Next
Set frm = Nothing
What is the error and what is it you are trying to do?
Yes. But, VB6 can't do that. You'd have to close the MDIForm that contained the Children.
I have never saw this used
If I was wanting to unload the children of a mdi form I would use the Unload methodCode:MDIMainForm.RemoveChild frm.Name ' Error here
if I use Unload the following Unload I have must to put the correct name of FormChild. eg MDIForm have Form1, Form2, ... Formn:
unload Form1
unload Form2
...
unload Formn
Now, I want to replace the code above with:
Dim frm As Form
' Close many FormRemoveChild
For Each frm In Forms
If Me.Name <> frm.Name Then ' Me.Name is MDIForm and frm.Name is Form1, Form2, ...., Formn
Unload frm.Name ' Error here
End If
Next
Set frm = Nothing
What should I do ?
It would help if you would tell us what the error message is rather than just saying error here.
At any rate the problem is that you are using unload incorrectly
it should be
when you add the .name you are telling it to unload the name property of the form which is a string and of course that is not valid resulting in a type mismatchCode:unload frm
Example:
Create a new project with 2 forms form1 and form2
Add a button to form 1 and use the default name of command1
paste this code in form1 code window replacing any that is there already
run the program then click the buttonCode:Option Explicit
Private Sub Command1_Click()
Dim frm As Form
For Each frm In Forms
If frm.Name <> Me.Name Then
Unload frm
End If
Next
End Sub
Private Sub Form_Load()
Dim x As Integer
Dim frm As Form
For x = 1 To 10
Set frm = New Form2
frm.Show
Next
End Sub
it should create 10 copies of form 2 and then close them when you click the button leaving form 1 in tact
Ok, thank you very much