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

Getting A Reference To A Form Outside Creating Routine 1

Status
Not open for further replies.

boggg1

Programmer
Oct 17, 2002
102
EU
I have a form with a datagrid on it called frmDataForm. A new instance of this form is created every time I press a button to get data and the data is stored away in the new datagrid on the new form. The form of the creation command is...

Dim frmDataForm As New DataGridForm

The subroutine stops after the data form is created.

I can run this routine from a button as many times as I want, giving many forms of data. There will be as many forms (complete with datagrid and data) as times I have pressed the button.

My question is how do I get a reference to each newly created form from outside the creating routine so that I can shut all forms down with one button push. Perhaps I can store them in a collection as they are created then delete them something like this...

Private Sub DeleteAllDatagrids_Click()

Dim GridForm As Form

For Each GridForm In DataFormCollection
Unload GridForm
Next DataGridForm

End Sub

If this is right, what do I actually put into the collection to enable this bit of code to work ?

Thanks.

Boggg1
[bigglasses]
 
If all you are wanting to do is shut them down you don't need to implement a collection because vb already has a forms collection

Code:
Dim frm As Form

For Each frm In Forms
    If frm.Name = "The Name Of the Form" Then
        unload frm
    End If
Next
 
Doh !

Yes that works bjd4jc. Thanks. Have a star.

Boggg1
[bigglasses]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top