Solved

Unloading forms from forms collection..

Posted on 2004-04-12
5
127 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:Regulapati
  • 2
5 Comments
 
LVL 6

Expert Comment

by:mirzas
ID: 10808137
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)
...           ...         ...
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 10808177
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
0
 

Author Comment

by:Regulapati
ID: 10808242
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
0
 
LVL 17

Accepted Solution

by:
zzzzzooc earned 125 total points
ID: 10808379
>> So I think I need to get the "TestFormString" form name from some Kind of forms collection property

If you plan on loading/unloading forms based on "Test1"/"Test2" instead of their form names, you can use the form's Tag property to store the information for form enumeration.

Private Sub Command1_Click()
    Dim fForm As Form
    'loop through loaded forms
    For Each fForm In Forms
        If fForm.Tag = "Test3" Then
            'This is the loaded instance of Form3 (Test3)
            '
            'Unload it..
            Call Unload(fForm)
            Exit For
        End If
    Next fForm
End Sub
Private Sub Form_Load()
    Dim fForm As Form, sFormName As String, sFormID As String
    sFormName = "Form3"
    sFormID = "Test3"
    Call Forms.Add(sFormName)
    Set fForm = Forms.Item(Forms.Count - 1)
    fForm.Tag = sFormID
    Call fForm.Show
End Sub

0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ms access #TYPE! error on report when no data 4 77
Excel object stays open 19 76
VB6 ListBox Question 4 45
vbModal 12 53
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question