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 can I check if there is any form’s active.

Status
Not open for further replies.

ALSayegh

Programmer
Mar 27, 2001
25
0
0
KW
Hi

How can I check if there is any form’s active.
Exp.
I have main.frm and I want to check if other forms are
Working.
If yes I want to unload them.

I try this code it work :
If Myfrm.visibel = True then unload Myfrm

But there is problem that each time I run this code
VB will load the form “Myfrm” and this case it waste of time.

I hope Same one Can Help
Thanks
 

Dim frm As VB.Form

For Each frm in VB.Forms
unload frm

Next frm


Or

Do until VB.Forms.Count = 1
unload VB.Forms(VB.Forms.Count-1)
Loop
[/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!
 
Thanks Mr. CCLINT

But I want to now first if the form is Active
 
The above example will list only the forms which have been loaded. If you want to find out the current active form then use:

if Not MainForm.ActiveForm Is Nothing then
ActiveFormName = MainForm.ActiveForm.Name
End if

Or use the first example as in:

Dim frm As VB.Form

If Not MainForm.ActiveForm Is Nothing then

For Each frm in VB.Forms
If frm = MainForm.ActiveForm Then
'Do Something
End If

Next frm

End If
ActiveFormName = MainForm.ActiveForm.Name
End if

[/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!
 
I am grateful for your help

I get new information how to use ActiveForm property

But ActiveForm Work only with MDIForm

 
As long as you are using a MDI, you can access it's properties and methods from any form.

Other than that, the VB.Forms collection will show which form has been loaded. Then you can use in the first example:

frm.Visible or frm.zorder when looping though the forms collection to see if a form is visible or on top.

You can also use an API function to determine this, but, first you need to get a little more experience with the fundamentals of VB. [/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!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top