looping thru the buttons in an option group

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sparks

    looping thru the buttons in an option group

    well I am trying to get around looking at all the buttons with a case
    statement so I was trying this.

    Public Sub looking(ctlname )
    Dim ctl As OptionGroup
    Dim btn As ToggleButton
    ctl = Me.Controls(ctl name)
    =============== ==============
    For Each btn In ctl.children <<<< I know that the children doesn't
    make since .its just a note to myself..this is where I am stumped.
    I thought maybe ctl.controls but now shure what or how to loop thru
    these
    = =============== =============
    If btn.OptionValue = ctl.Value Then
    btn.ForeColor = 255
    Else
    btn.ForeColor = 0
    End If
    Next


    I was hoping to go thru the buttons in the option group and if it was
    the selected button change the foreground color.

    but I can't get the grasp of exactly what a button is in an
    optiongroup
  • Marshall Barton

    #2
    Re: looping thru the buttons in an option group

    sparks wrote:
    >well I am trying to get around looking at all the buttons with a case
    >statement so I was trying this.
    >
    >Public Sub looking(ctlname )
    >Dim ctl As OptionGroup
    >Dim btn As ToggleButton
    >ctl = Me.Controls(ctl name)
    >============== ===============
    >For Each btn In ctl.children <<<< I know that the children doesn't
    >make since .its just a note to myself..this is where I am stumped.
    >I thought maybe ctl.controls but now shure what or how to loop thru
    >these
    >= =============== =============
    If btn.OptionValue = ctl.Value Then
    btn.ForeColor = 255
    Else
    btn.ForeColor = 0
    End If
    >Next

    For Each btn In ctl.Controls

    --
    Marsh

    Comment

    • sparks

      #3
      Re: looping thru the buttons in an option group

      On Thu, 01 May 2008 14:39:53 -0500, Marshall Barton
      <marshbarton@wo wway.comwrote:
      >sparks wrote:
      >
      >>well I am trying to get around looking at all the buttons with a case
      >>statement so I was trying this.
      >>
      >>Public Sub looking(ctlname )
      >>Dim ctl As OptionGroup
      >>Dim btn As ToggleButton
      >>ctl = Me.Controls(ctl name)
      >>============= =============== =
      >>For Each btn In ctl.children <<<< I know that the children doesn't
      >>make since .its just a note to myself..this is where I am stumped.
      >>I thought maybe ctl.controls but now shure what or how to loop thru
      >>these
      >>= =============== =============
      > If btn.OptionValue = ctl.Value Then
      > btn.ForeColor = 255
      > Else
      > btn.ForeColor = 0
      > End If
      >>Next
      >
      >
      >For Each btn In ctl.Controls


      now I get this on
      ctl = Me.Controls(ctl name)
      object variable or with block variable not set.

      I am calling this with looking ("Q23Pass1Posit ion")
      passing a string as the control name I assume either this is wrong or
      I am missing a library.

      Comment

      • Marshall Barton

        #4
        Re: looping thru the buttons in an option group

        sparks wrote:
        >On Thu, 01 May 2008 14:39:53 -0500, Marshall Barton
        ><marshbarton@w owway.comwrote:
        >
        >>sparks wrote:
        >>
        >>>well I am trying to get around looking at all the buttons with a case
        >>>statement so I was trying this.
        >>>
        >>>Public Sub looking(ctlname )
        >>>Dim ctl As OptionGroup
        >>>Dim btn As ToggleButton
        >>>ctl = Me.Controls(ctl name)
        >>>============ =============== ==
        >>>For Each btn In ctl.children <<<< I know that the children doesn't
        >>>make since .its just a note to myself..this is where I am stumped.
        >>>I thought maybe ctl.controls but now shure what or how to loop thru
        >>>these
        >>>= =============== =============
        >> If btn.OptionValue = ctl.Value Then
        >> btn.ForeColor = 255
        >> Else
        >> btn.ForeColor = 0
        >> End If
        >>>Next
        >>
        >>
        >>For Each btn In ctl.Controls
        >
        >
        >
        >now I get this on
        >ctl = Me.Controls(ctl name)
        >object variable or with block variable not set.
        >
        >I am calling this with looking ("Q23Pass1Posit ion")
        >passing a string as the control name I assume either this is wrong or
        >I am missing a library.

        Neither. The error is because you have to use Set with
        object valiables:
        Set ctl = Me.Controls(ctl name)

        Another way (preferable IMO) is to use:

        Public Sub looking(ctl As OptionGroup)
        Dim btn As ToggleButton
        For Each btn In ctl.Controls

        And call it:
        looking Me.Q23Pass1Posi tion

        When calling a Sub procedure with just the procedure name,
        don't use ( ) The ( ) won't work with a list of argumnets
        and in your case above, they will convert the control object
        to its Value property.

        You do need ( ) if you call it this way:
        Call looking(Me.Q23P ass1Position)

        --
        Marsh

        Comment

        • sparks

          #5
          Re: looping thru the buttons in an option group

          Thank you very much for clearing that up for me.
          Will give it a try right now.

          again thanks for taking the time to explain it all.


          On Fri, 02 May 2008 17:28:34 -0500, Marshall Barton
          <marshbarton@wo wway.comwrote:
          >sparks wrote:
          >
          >>On Thu, 01 May 2008 14:39:53 -0500, Marshall Barton
          >><marshbarton@ wowway.comwrote :
          >>
          >>>sparks wrote:
          >>>
          >>>>well I am trying to get around looking at all the buttons with a case
          >>>>statement so I was trying this.
          >>>>
          >>>>Public Sub looking(ctlname )
          >>>>Dim ctl As OptionGroup
          >>>>Dim btn As ToggleButton
          >>>>ctl = Me.Controls(ctl name)
          >>>>=========== =============== ===
          >>>>For Each btn In ctl.children <<<< I know that the children doesn't
          >>>>make since .its just a note to myself..this is where I am stumped.
          >>>>I thought maybe ctl.controls but now shure what or how to loop thru
          >>>>these
          >>>>= =============== =============
          >>> If btn.OptionValue = ctl.Value Then
          >>> btn.ForeColor = 255
          >>> Else
          >>> btn.ForeColor = 0
          >>> End If
          >>>>Next
          >>>
          >>>
          >>>For Each btn In ctl.Controls
          >>
          >>
          >>
          >>now I get this on
          >>ctl = Me.Controls(ctl name)
          >>object variable or with block variable not set.
          >>
          >>I am calling this with looking ("Q23Pass1Posit ion")
          >>passing a string as the control name I assume either this is wrong or
          >>I am missing a library.
          >
          >
          >Neither. The error is because you have to use Set with
          >object valiables:
          > Set ctl = Me.Controls(ctl name)
          >
          >Another way (preferable IMO) is to use:
          >
          >Public Sub looking(ctl As OptionGroup)
          >Dim btn As ToggleButton
          > For Each btn In ctl.Controls
          >
          >And call it:
          > looking Me.Q23Pass1Posi tion
          >
          >When calling a Sub procedure with just the procedure name,
          >don't use ( ) The ( ) won't work with a list of argumnets
          >and in your case above, they will convert the control object
          >to its Value property.
          >
          >You do need ( ) if you call it this way:
          > Call looking(Me.Q23P ass1Position)

          Comment

          Working...