Link to home
Start Free TrialLog in
Avatar of Regulapati
Regulapati

asked on

Unloading forms from forms collection..

Hi ,
Couple of days back I asked a question about loading the forms from a database field
and I got a quick answer from Shauli.
Now I have one more question about the unloading or hiding the forms from the forms collection,
In the Database I have like this
System          Form
Test1            frmTest
Test2            frmTest
Test3            frmTest1
Point out that we are using same forms for both test1 and test2 systems.
When I Load the forms with out Modal(vform.show) users can load more than one form
at a time.
EX: User Loaded the form for Test1 System with out closing the this form, user loaded the
form for second system also.
Now If the User want to Close the Form for Test1 system , With my code It is closing the second form
  Set vForm1 = Forms(Forms.Count - 1)
  Unload vForm1
I know that here it is picking up the last forms count and closing the last form, but how can
i get the Count or index of the form for the test1 system.

Any help is gratly appriciated
Thanks
ML
Avatar of mirzas
mirzas
Flag of Bosnia and Herzegovina image

If I understood correctly, you can extend your database to hold HWND of each form.. that way you can identify active forms


System    Form    HWND(ID)
...           ...         ...
Avatar of zzzzzooc
zzzzzooc

If all you want to do is get the instance of a loaded form, you can loop through the forms collection and match each name against the name you're after..

Form1:
========

Private Const TestFormString As String = "Form3"
Private Sub Command1_Click()
    Dim fTestForm As Form
    'loop through loaded forms
    For Each fTestForm In Forms
        If fTestForm.Name = TestFormString Then
            'This is the loaded instance of Form3
            '
            'Unload it..
            Call Unload(fTestForm)
            Exit For
        End If
    Next fTestForm
End Sub
Private Sub Form_Load()
    Dim fTestForm As Form
    Call Forms.Add(TestFormString)
    Set fTestForm = Forms.Item(Forms.Count - 1)
    Call fTestForm.Show
End Sub
Avatar of Regulapati

ASKER

Hi ZZZZZOC,

Thanks for the reply,
But until User clicks the form I donot know which form he is going to click,
So I think I need to get the "TestFormString" form name from some Kind of forms collection property

Mirzas,
I am going to try the one which you suggested..

Thanks
ML
ASKER CERTIFIED SOLUTION
Avatar of zzzzzooc
zzzzzooc

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial