Results 1 to 3 of 3

Thread: forms collection?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    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

  2. #2
    Fanatic Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    1,008
    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.
    Not nearly so tired now...

    Haven't been around much so be gentle...

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width