 |
confusedbrat Level: Sage
 Registered: 29-08-2005 Posts: 64
|
closing forms
Hey ppl
i have a couple of questions....
1. i created an exe with many forms in it. i have the buttons for all the forms in the main form and just show and hide them. when i close the exe program from the main page, the program is closed but then when i close it from other pages, though it is closed, when i go to the task manager, it is still running. Is there a way to stop the program from other pages also.
2. when i hit a drop down button with some commands inside it, the first time when i do that it just comes and goes and then the second time it stays. guess i am not clear. the first time it just drops down and rolls back immediately. when i hit it the second time it drop downs and stays open. this happens to all the buttons which has somethin inside the combo_click.
Please help me out.
thanx
brat
|
|
11-12-2005 at 07:54 PM |
|
|
yronium Level: Moderator

 Registered: 14-04-2002 Posts: 907
|
Re: closing forms
Hello.
1) I suggest you to create in a module a public routine like following: Public Sub CloseAllForms(CallingForm As Form)
Dim frm As Form
For Each frm in Forms
If Not frm.Name = CallingForm.Name Then Unload frm
Next frm
End Sub | Then, you can implement a feature to call it from any form you need. Just call it as followingPrivate Sub btnCloseAll_Click()
' unload any other open form first
CloseAllForms Me
' at the end, unload the calling form (it has to be unloaded after all the others)
Unload Me
End Sub |
The working criteria is to surf the Forms collection, that's containing all the loaded forms. There are several ways for doing it. An alternative way is by referring to the Forms.Count property.Private Sub Form_Unload()
Dim i As Long
For i = Forms.Count - 1 To 0 Step -1
Unload Forms(i)
Next i
End Sub | You can use this second method if you put the CloseAll feature only into one single form, and always go to this point to stop the entire program run. In this case, you have to unload all the forms, including the calling form, and the routine above does so.
When dealing with an MDI project, you can just unload the MDIParent form and all the non-MDIChild forms.
2) It could depend on what it happens during dropdown. Say, if you add some records without deleting the existing ones, and maybe you re-compute some data, requery some other combos and controls, it's normal if it takes time. The more time is needed because now the records are more than before.
But we can't know it, only trying to figure it out. You only know what you have put down in code.
Hope it helps
____________________________
Real Programmer can count up to 1024 on his fingers
|
|
11-12-2005 at 09:01 PM |
|
|
confusedbrat Level: Sage
 Registered: 29-08-2005 Posts: 64
|
Re: closing forms
Hey
thanx for the reply, i understand what you do, but got couple of questions. What is the sub btncloseall_click . is that a button that i need to create to close the application. actually i was askin abt the X button on the right top. I want to close all forms when they hit that button. How can i do that.
thanx
brat
|
|
11-12-2005 at 09:33 PM |
|
|
confusedbrat Level: Sage
 Registered: 29-08-2005 Posts: 64
|
Re: closing forms
hey
thanx for ur idea...
i have somethin like this
sub btn_click
first.hide
second.show
end sub
how do i change it if i want to unload
just put
sub btn_click
second.show
unload me
end sub
is it how i do?
thanx
|
|
11-12-2005 at 10:59 PM |
|
|
yronium Level: Moderator

 Registered: 14-04-2002 Posts: 907
|
Re: closing forms
quote: confusedbrat wrote:
.... actually i was askin abt the X button on the right top. I want to close all forms when they hit that button....
...so, you want to unload all forms when unloading a certain one.
Put the public routine in a module...
Public Sub CloseAllForms(CallingForm As Form)
Dim frm As Form
For Each frm in Forms
If Not frm.Name = CallingForm.Name Then Unload frm
Next frm
End Sub |
... then put the call to the CloseAllForms routine in form's Unload event
Private Sub Form_Unload()
' unload any other open form first
CloseAllForms Me
' at the end, unload the calling form (it has to be unloaded after all the others)
Unload Me
End Sub |
If you do it, say, in Form1, Form2 and Form3, when you close any of these three forms you unload the whole application. I mean, you can't just unload none of these three forms without closing the whole app, so you better choose carefully what forms you have to put the call in: you should put the call only in the last form to unload, so this form should always be the same. Usually I design a main form and prevent user to close it. I put the Exit feature there, and all the other forms point to this one. Every other form can only unload itself, but when the main one is unloaded every other one is unloaded too. However, it's just a hint.
Hope it helps
____________________________
Real Programmer can count up to 1024 on his fingers
|
|
11-12-2005 at 11:01 PM |
|
|
confusedbrat Level: Sage
 Registered: 29-08-2005 Posts: 64
|
Re: closing forms
hey
on my second question, for example i have this
Private Sub Combo1_Click()
Combo2.Clear
List7.Clear
List8.Clear
List9.Clear
List10.Clear
List11.Clear
List2.Clear
List12.Clear
Combo5.Clear
List1.Clear
SQLStr9 = "Select DISTINCT fname from finalweeksel where suppliercode = " + "'" + Combo1.Text + "'"
Set datecalc = OpenDatabase(App.Path & "\datecalc.mdb")
Set RecSet9 = datecalc.OpenRecordset(SQLStr9)
While Not RecSet9.EOF()
Combo2.AddItem (RecSet9.Fields(0))
RecSet9.MoveNext
Wend
RecSet9.Close
datecalc.Close
SQLStr1 = "Select suppliername, suppliercode from supplier where suppliercode = " + "'" + Combo1.Text + "'"
Set dn = OpenDatabase(App.Path & "\datecalc.mdb")
Set RecSet1 = dn.OpenRecordset(SQLStr1)
txtName.Text = RecSet1.Fields(0)
RecSet1.Close
End Sub |
when i click on this drop down the first time, i can see all the items in the drop down but it roll backs immediately in a second and then when i click it the next time it stays. is there somethin wrong i do.
thanx
brat
|
|
11-12-2005 at 11:02 PM |
|
|
MaxMouse Level: Protégé
 Registered: 04-01-2006 Posts: 6
|
Re: closing forms
if you want to close all forms on exit of the main application
just put:
in the unload section of each of your forms
and in the main form (used to load all other forms)
put:
You don't really need to worry too much about setting all the other forms to nothing, its recommended but not entirely needed. so basically on your main form's unload sub just stick an "End"
|
|
04-01-2006 at 01:35 PM |
|
|
|
|
 |
 |