469,306 Members | 1,884 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

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(ctlname)
=============================
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
Jun 27 '08 #1
4 4715
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(ctlname)
=============================
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
Jun 27 '08 #2
On Thu, 01 May 2008 14:39:53 -0500, Marshall Barton
<ma*********@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(ctlname)
=============================
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(ctlname)
object variable or with block variable not set.

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

Jun 27 '08 #3
sparks wrote:
>On Thu, 01 May 2008 14:39:53 -0500, Marshall Barton
<ma*********@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(ctlname)
=============================
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(ctlname)
object variable or with block variable not set.

I am calling this with looking ("Q23Pass1Position")
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(ctlname)

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.Q23Pass1Position

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.Q23Pass1Position)

--
Marsh
Jun 27 '08 #4
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
<ma*********@wowway.comwrote:
>sparks wrote:
>>On Thu, 01 May 2008 14:39:53 -0500, Marshall Barton
<ma*********@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(ctlname)
=============================
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(ctlname)
object variable or with block variable not set.

I am calling this with looking ("Q23Pass1Position")
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(ctlname)

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.Q23Pass1Position

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.Q23Pass1Position)
Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by TORQUE | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.