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

Finding Active Forms 1

Status
Not open for further replies.

rickkcir

Technical User
Jul 31, 2002
35
I have an application that shows a form that has a report on it if you press a button. I have another identical form that also shows a report (a second report would be selected, so while the form is identical, the report on the form would not be). I would like to be able, when the button is pressed, to figure out if the first form is open, and if it is, then open the second form. Obviously, if the first firm is not open, I want it to open the first form.

Any help would be appreciated. Thanks.
 
I got this from this site some time ago - hopefully it will help

Dim frm as Form

for each frm in Forms
if frm.name = "FormB" then
.
.
end if
next
 
You might be able to get this information from the Forms collection. If the first form is not found in the collection, then it has not been loaded.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Thank you very much TomKane for the response....it worked perfectly.

Does anyone know if this is possible to do with more than 2 forms. I've played around with the code quite a bit and can't get anything to work.

Basically, what I need to do is have the program check if form 1 is open, if it is open form 2, but if form 1 and 2 are open, then open form 3. Or if they had all 3 forms up, and then closed one, for the program to see that form 2 and 3 are already up, so open form 1.

Thanks in advance for any responses.
 
Uff. I would recommend a different method, such as loading the sub forms form the parent form in the parent form's load event, or whatever, and unloading the child forms in the parents Unload event, and having each parent form keep track of it's child form by using form object variables in the perent form.
That way you could open multiple copies of the same parent forms, each with their own copy of the child forms.

The way you are asking would mean each form could be opened only once with-out conflicts arising.

But...here goes anyways!!!:

Dim i As Integer
Dim frm As VB.Form
Dim frmType As VB.Form
Dim bFormIsLoad As Boolean

For i = 0 To 2
Select Case i
Case 0
Set frmType = Form2
Case 1
Set frmType = Form3
Case 2
Set frmType = Form4
End Select
For Each frm In VB.Forms
If frm Is frmType Then
'Form2 is loaded
bFormIsLoad = True
Exit For
End If
Next frm
If Not bFormIsLoad Then frmType.Show
bFormIsLoad = False
Next i
Set frmType = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top