PC Review


Reply
Thread Tools Rate Thread

Counting/Changing multiple buttons?

 
 
=?Utf-8?B?UGF1bFc=?=
Guest
Posts: n/a
 
      30th Apr 2007
I'm making a userform, and with each userform everything gets more complete
with more options.

An example was a recent one with 21 togglebuttons.

What i'm wanting to be able to do is to easy change all the togglebuttons to
FALSE, or count how many are on true.
To switch them all i've had to put a line of code for each, setting them to
false individually.
To count them all I've had to set a variable, and check each one
individually, and if its TRUE add 1 to the variable.

Is there a simple way to either use a global command to change/count every
togglebutton, or a simple way to loop through them all?

sub change()
for each togglebox in userform
let value = false
next
end sub

sub change()
for i = 1 to 21
let togglebox & i value = false
next
end sub

Are a couple of things I tried unsuccessfully...
 
Reply With Quote
 
 
 
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      30th Apr 2007
Paul,

try something like this:

Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is ToggleButton Then
ctrl.Value = Not ctrl.Value
End If
Next ctrl


--
Hope that helps.

Vergel Adriano


"PaulW" wrote:

> I'm making a userform, and with each userform everything gets more complete
> with more options.
>
> An example was a recent one with 21 togglebuttons.
>
> What i'm wanting to be able to do is to easy change all the togglebuttons to
> FALSE, or count how many are on true.
> To switch them all i've had to put a line of code for each, setting them to
> false individually.
> To count them all I've had to set a variable, and check each one
> individually, and if its TRUE add 1 to the variable.
>
> Is there a simple way to either use a global command to change/count every
> togglebutton, or a simple way to loop through them all?
>
> sub change()
> for each togglebox in userform
> let value = false
> next
> end sub
>
> sub change()
> for i = 1 to 21
> let togglebox & i value = false
> next
> end sub
>
> Are a couple of things I tried unsuccessfully...

 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      30th Apr 2007
Sub change()
Dim ctl As Control

For Each ctl In Me.Controls
'If TypeName(ctl) = "ToggleButton" Then
'or
If TypeOf ctl Is MSForms.ToggleButton Then
ctl.Value = False
End If
Next

If all the togglebuttons have similar names, eg ToggleButton-X

For i = 1 To 21
Me.Controls("ToggleButton" & i).Value = True
Next


If at design time you place your togglebuttons on the form consequtively you
can loop controls by Index. The Index of the first added control is 0. The
index numbers will never change (cannot be changed) EXCEPT if you delete a
control, then the index of each subseqent control will increment down by
one.

So, if say the first added control is your Cancel button, then you added 21
Togglebuttons you could do this

For i = 1 To 21
Me.Controls(i).Value = False
Next

Regards,
Peter T

"PaulW" <(E-Mail Removed)> wrote in message
news:E9B14749-55BA-4F77-87D6-(E-Mail Removed)...
> I'm making a userform, and with each userform everything gets more

complete
> with more options.
>
> An example was a recent one with 21 togglebuttons.
>
> What i'm wanting to be able to do is to easy change all the togglebuttons

to
> FALSE, or count how many are on true.
> To switch them all i've had to put a line of code for each, setting them

to
> false individually.
> To count them all I've had to set a variable, and check each one
> individually, and if its TRUE add 1 to the variable.
>
> Is there a simple way to either use a global command to change/count every
> togglebutton, or a simple way to loop through them all?
>
> sub change()
> for each togglebox in userform
> let value = false
> next
> end sub
>
> sub change()
> for i = 1 to 21
> let togglebox & i value = false
> next
> end sub
>
> Are a couple of things I tried unsuccessfully...



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing interactive buttons back to buttons in original theme. Chris Microsoft Frontpage 2 23rd Jun 2006 09:42 AM
report counting option buttons kathy Microsoft Access Reports 7 29th Sep 2004 04:11 AM
options/ Voting / Radio buttons counting Gbarnes1 Microsoft Excel Discussion 1 3rd Dec 2003 12:26 AM
Excel Help - Counting Multiple Conditions & Multiple Values MAX258 Microsoft Excel Worksheet Functions 7 13th Oct 2003 09:45 PM
Excel Help - Counting Multiple Conditions & Multiple Values MAX258 Microsoft Excel Worksheet Functions 0 13th Oct 2003 07:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:07 PM.