Consulting

Results 1 to 3 of 3

Thread: How to check whether a control is having a property?

  1. #1

    How to check whether a control is having a property?

    Say Controlsource.
    For a single control its easy
    On Error Resume Next
    Msgbox Control.Controlsource
    Msgbox "Control Don't have that property"

    The problem comes here,
    For each control in codecontextobject.controls
    On Error Goto NextControl
    Msgbox Control.Controlsource
    Nextcontrol:
    Next control

    I want to know either how to trap continous errors else some workaround for this. Kindly help.

  2. #2
    VBAX Expert Imdabaum's Avatar
    Joined
    Jun 2006
    Posts
    652
    Location
    Is this related to your previous post on identifying which controls have controlsource?

    If not, then I would suggest running it once and instead
    [vba]On Error Goto NextControl
    Msgbox Control.Controlsource
    Nextcontrol:
    Next control[/vba]

    Try:
    [vba]On Error Goto NextControl
    Msgbox Control.Controlsource
    Nextcontrol:
    Msgbox Err.Number
    Next control[/vba]

    This will let you see the error number you need to trap.
    Then in
    [vba]
    NextControl:
    If Err.number = [insert the number you receive from the message box]
    'Ignore the fact that the control doesn't have the property, and don't do anything.
    'Just get the next control
    Resume Next
    Else
    'show the error and take appropriate actions to fix your code/data.
    Exit Sub/Function
    End If
    [/vba]
    Someday I'll understand everything...
    Even then...I'll still pretend I'm a beginner.

  3. #3
    VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    This has already been answered here. You use ControlType to restrict your loop to the types of controls that will have a data source.

    We are what we repeatedly do. Excellence, therefore, is not an act but a habit.
    Aristotle

Posting Permissions

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