none
is there a way to know the type of control

    Question

  • dim ctl as control

    for each ctl in me.controls

    ...

    ...

    next

    is there a way to know whether ctl is a label, checkbox, combo box, text box, etc...


    For the benefit of others, please mark posts as answered or helpful when they answer or assist you in finding the answer. ___ "We came all this way to explore the Moon, and the most important thing is that we discovered the Earth." - Bill Anders, Apollo 8.
    Tuesday, October 25, 2011 11:34 PM

Answers

  • Another option is to use the TypeName function.

    Dim ctl As Control
    For Each ctl In Me.Controls
        ' Use TypeName
        Debug.Print ctl.Name & " is of type " & TypeName(ctl)
    Next ctl
    

     

    TypeName results in strings such as "TextBox", "ListBox", "Label" etc.
    Regards, Hans Vogelaar
    • Proposed as answer by VanderghastModerator Wednesday, October 26, 2011 1:43 PM
    • Marked as answer by -suzyQ Wednesday, October 26, 2011 3:35 PM
    Wednesday, October 26, 2011 12:02 PM
  • Yes, you can check the type by checking the ControlType, something like this:

    For Each ctl In Me.Controls
             
             If ctl.ControlType = acTextBox Then
              MsgBox "Its a TextBox"
           ' acComboBox
           ' acListBox  
               
    Next ctl
    


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Wednesday, October 26, 2011 12:06 AM
  • I don't remember if it was true in earlier versions, but in Access 2010 SP1 intellisense does not show this property. Type it in without intellisense, and the project will compile. Putting your cursor within the property name and pressing F1 correctly brings up the property help.
    • Marked as answer by -suzyQ Wednesday, October 26, 2011 3:35 PM
    Wednesday, October 26, 2011 11:35 AM
  • The same was true for previous version: IntelliSense does not show ControlType in the popup list of properties and methods of a variable of type Control. It does for variables of type TextBox, TabControl etc. (but for those it is superfluous).
    Regards, Hans Vogelaar
    • Marked as answer by -suzyQ Wednesday, October 26, 2011 3:35 PM
    Wednesday, October 26, 2011 11:55 AM

All replies

  • Yes, you can check the type by checking the ControlType, something like this:

    For Each ctl In Me.Controls
             
             If ctl.ControlType = acTextBox Then
              MsgBox "Its a TextBox"
           ' acComboBox
           ' acListBox  
               
    Next ctl
    


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Wednesday, October 26, 2011 12:06 AM
  • I must have missed that as I was scrolling through the intellisense.  I will check it out tomorrow.  Thanks.
    For the benefit of others, please mark posts as answered or helpful when they answer or assist you in finding the answer. ___ "We came all this way to explore the Moon, and the most important thing is that we discovered the Earth." - Bill Anders, Apollo 8.
    Wednesday, October 26, 2011 5:38 AM
  • I don't remember if it was true in earlier versions, but in Access 2010 SP1 intellisense does not show this property. Type it in without intellisense, and the project will compile. Putting your cursor within the property name and pressing F1 correctly brings up the property help.
    • Marked as answer by -suzyQ Wednesday, October 26, 2011 3:35 PM
    Wednesday, October 26, 2011 11:35 AM
  • The same was true for previous version: IntelliSense does not show ControlType in the popup list of properties and methods of a variable of type Control. It does for variables of type TextBox, TabControl etc. (but for those it is superfluous).
    Regards, Hans Vogelaar
    • Marked as answer by -suzyQ Wednesday, October 26, 2011 3:35 PM
    Wednesday, October 26, 2011 11:55 AM
  • Another option is to use the TypeName function.

    Dim ctl As Control
    For Each ctl In Me.Controls
        ' Use TypeName
        Debug.Print ctl.Name & " is of type " & TypeName(ctl)
    Next ctl
    

     

    TypeName results in strings such as "TextBox", "ListBox", "Label" etc.
    Regards, Hans Vogelaar
    • Proposed as answer by VanderghastModerator Wednesday, October 26, 2011 1:43 PM
    • Marked as answer by -suzyQ Wednesday, October 26, 2011 3:35 PM
    Wednesday, October 26, 2011 12:02 PM