473,573 Members | 2,753 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Jun 27 '08 #1
4 5119
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
Jun 27 '08 #2
On Thu, 01 May 2008 14:39:53 -0500, Marshall Barton
<ma*********@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.

Jun 27 '08 #3
sparks wrote:
>On Thu, 01 May 2008 14:39:53 -0500, Marshall Barton
<ma*********@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
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*********@wo wway.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(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)
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
4801
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 to hit - they don't work at all. Its true. I created 'em with the built-in wizard furnished with Access 97 but they do not work. I put 12 of 'em...
5
2661
by: tsnyder | last post by:
I need to have an option button that allows editing to a field only when it is checked.
3
4140
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 a particular location if button 2 is pressed a file will be imported from a different location. I have several buttons but figure if someone can...
3
3051
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
8757
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 up with this code and the way I set it up the first button is my search toggle button no submenu (this prevents a submenu from displaying when the...
3
18576
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 toolbox called an Option Group. It could contain any number of radio buttons (which Access called Option Buttons), each of which had a "value" property. ...
5
3672
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 total number showen on screen, or on "submit" loop through the selected radio buttons and get the total. What I have at the moment will loop...
2
5253
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 duplicate the action in Access. Chuck
2
3400
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 member combo boxes. I have an option group that has 4 option buttons for the user to indicate how many staff members to include. Once the user selects...
0
7788
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7707
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7799
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8080
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6430
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5296
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3742
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1048
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.