-
Hi,
I'm trying to learn about referencing controls on a form from a module.
I know there is something called the forms collection which contains all the controls that are on a particular form, but I don't know how to use that..
For example, say I have a form with several text boxes, listviews and command buttons. In my module, say I want to count the number of listviews on a particular form and also find out the tags of each listviews.
This is just to help me learn this subject.. Any help and examples would be greatly appreciated..
Dan
-
You can use Forms("FormName") or use a number to access the open forms. You can then access the controls collection of the form.
e.g.
Code:
Dim frm As Form
Set frm = Forms("MyForm")
Dim ctl As Control
Dim iLVCount as Integer
For Each ctl in frm.Controls
If TypeOf(ctl) Is ListView then
iLVCount = iLVCount
Debug.Print ctl.Tag
End If
Next i
Hope that helps.
Paul.
-
Thanks, but I get an error when I use your code..
It tells me there's a type mismatch at:
Set frm = Forms("frmMain")
Any ideas? I'm using VB6..
Thanks,
dan