How do I reference a control, not its default property

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • flap152
    New Member
    • Nov 2009
    • 1

    How do I reference a control, not its default property

    I'm trying to build a collection of a few controls (a subset of controls from a report in Access) for later use in a foreach statement

    Code:
    Dim ControlList1 As New Collection ' to hold controls for formating
    ControlList1.Add (tbRevision) ' does not work
    ControlList1.Add (Me.Controls("tbChecklist"))  ' does not work either
    The collection gets the value of the default property for the control (a string), instead of the control itself.

    So, how do I reference a control, not its default property?
  • vb5prgrmr
    Recognized Expert Contributor
    • Oct 2009
    • 305

    #2
    In Visual Basic 6.0 you can do something like...
    Code:
    Option Explicit
    
    Dim O(1 To 2) As Object
    
    Private Sub Form_Load()
    Set O(1) = Command1
    Set O(2) = Text1
    End Sub
    
    Private Sub Command1_Click()
    O(1).Caption = "Click"
    O(2).Text = "Changed"
    End Sub
    That is just one way but I hope it helps you figure out your quandry.



    Good Luck

    Comment

    • QVeen72
      Recognized Expert Top Contributor
      • Oct 2006
      • 1445

      #3
      Hi,

      You have to declare the control and use "SET"

      Dim Ctl As Control
      Set Ctl = Me.Controls("Te xtBox1")


      Regards
      Veena

      Comment

      Working...