[RESOLVED] Referring to form in class of forms
Hello all,
Feel like this is a silly question, but I have not been able to find the answer.
Say, I have a form called frmClass, from which I instantiate 2 forms at run time:
Public frm1 As New frmClass
Public frm2 As New frmClass
If I issue the Me. keyword in source code, it responds with "frmClass" rather than "frm1" or "frm2".
How do I make reference to the instantiated forms within the class?
Re: Referring to form in class of forms
Just replace 'Me' with the name of the instantiated Object
eg
Code:
Option Explicit
Private frm1 As New Form1
Private frm2 As New Form1
Private Sub Command_Click()
Debug.Print Hex(frm1.hWnd)
Debug.Print Hex(frm2.hWnd)
End Sub
Re: Referring to form in class of forms
You can also do something like putting a unique value in the form's Tag property when it is created and then iterating through the Forms collection looking for the tag with the value you want. So something like this:
Code:
Private frm1 As New Form1
frm1.Tag = "frm1"
Private frm2 As New Form1
frm2.Tag = "frm2"
Private Sub Command_Click()
Dim frm As Form
For Each frm in Forms
If frm.Tag = "frm1" Then
Debug.Print Hex(frm.hWnd)
Exit For
End If
Next
End Sub
Re: Referring to form in class of forms