Consulting

Results 1 to 2 of 2

Thread: Control.ControlType

  1. #1

    Control.ControlType

    Sorry for the newb questoin, So I cannot understand why I see all over the internet code below:
    dim ctl as Control
    ctl.ControlType
    or something similiar like
    dim ctl as Control
    For each ctl in Me.Controls
    if ctl.ControlType ........
    end if
    next
    How are people getting the ControlType Method in Control? When I try ctl.ControlType <---- this isn't one of its methods listed.
    Do you just pretend that it exist and hope it takes it?

    Edit:
    It works, but I just want to know why it doesn't recognize those methods. Like .ControlType, .Value, .Tag, etc

  2. #2
    Quote Originally Posted by jediderek View Post
    Sorry for the newb questoin,
    No need to apologize. Forums, like this one, are here to answer your questions.

    You learn by asking questions. So keep on asking ….


    Quote Originally Posted by jediderek View Post
    So I cannot understand why I see all over the internet code below:
    dim ctl as Control
    ctl.ControlType
    or something similiar like
    dim ctl as Control
    For each ctl in Me.Controls
    if ctl.ControlType ........
    end if
    next
    How are people getting the ControlType Method in Control? When I try ctl.ControlType <---- this isn't one of its methods listed.
    Do you just pretend that it exist and hope it takes it?

    Edit:
    It works, but I just want to know why it doesn't recognize those methods. Like .ControlType, .Value, .Tag, etc
    Great question.

    What you are referring to is called Intellisense. In the Visual Basic Editor (VBE) when you type something, it looks to see if it can determine what you are doing and offer help.

    The issue with using a generic object is that the VBE can’t help.

    Dim ctl as Control   ‘ creates a place to store many different control types
    Unfortunately, for Intellisense a variable of type Control is not specific enough to be allow it to offer any help.
    In this cases, it is up to the programmer to know what options are available.

    Just because intellisense can’t help you do not mean it is not valid code. The compiler can still recognize it as valid code and it will execute.

    Intellisense works great for standard VBA functions and other specific pieces of code. It does have limits when you start writing code beyond that.


    ' create an variable that is the type of Control 
    ' this can hold any control type
    '
    Dim ctl As Control 
    
    ' loop through all the controls on the current form or report (Me)
    For each ctl In Me.Controls 
       
        ' need to test the type of control to see if it is one that has the property/method we can to work with
        If ctl.ControlType = ........  Then 
       
       End If 
    
    Next
    In the code above, Intellisense can't determine at design time what the type of control. There can be many types of control on the form or report. There really is no way at design time for the Intellisense to know what type of control’s help to display. This is where the Programmer, a Human, is required to know what is needed.
    Boyd Trimmell aka HiTechCoach
    Microsoft Access MVP -2010-2015

    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

Posting Permissions

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