473,322 Members | 1,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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 5086
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: MLH | last post by:
Why is that? If I choose the tiny check boxes which are hard to hit with a mouse, it works fine. But option buttions, shich can be sized big enough for people with limited sight and dexterity...
5
by: tsnyder | last post by:
I need to have an option button that allows editing to a field only when it is checked.
3
by: Andrew | last post by:
I am new to VBA Please can someone help get me started. I need to know how to use an if statement to check if a button has been pressed i.e. if button 1 is pressed a file will be imported from...
3
by: TORQUE | last post by:
Hi How can I make a radio button create an action like enabling or disabling a delete button in a form? TIA TORQUE
0
Denburt
by: Denburt | last post by:
This code is for a Toggle Button layout on a form, with this code you can set a number of toggle buttons visible and have multiple submenus that will stay hidden when not in use. My main menu is set...
3
by: teddysnips | last post by:
Back in the dim mists of antiquity I used to program in VBA for Microsoft Access (hey, don't knock it - very useful tool for the right application). This had a really handy control in the...
5
by: alanb | last post by:
Hi, hope someone can help, I need to be able to keep a running total of radio buttons selected, as a user goes through a set of 16 questions, devided in to 4 catorgories, then on "submit" have the...
2
by: Chuck | last post by:
How can I make an array of command buttons (or toggle buttons) on a form and have a text box on the same form display the index of the button clicked? This works very well in VB6, but I can't...
2
beacon
by: beacon | last post by:
Hi everybody, I have a form that has a combo box that asks the user to select the program they work on. Once the user selects the program, a SQL statement populates the row source for 4 staff...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.