PC Review


Reply
Thread Tools Rate Thread

Arrays of Controls

 
 
NoSpam@aol.com
Guest
Posts: n/a
 
      4th Jun 2010
I would like to create a form with a large number of checkboxes. I would
like to be able to set their values and possibly other properties and
retrieve their values in a look rather than have long strings of code
reference each checkbox bt name. Is there any way to accomplish that?

Thank you.
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      4th Jun 2010
I think the answer is gonna depend on what kind of checkboxes these are and
where they're located.

If they're checkboxes from the Forms toolbar and they're placed on a sheet, you
could loop through them with something like this:

Option Explicit
Sub testme()
dim cbx as checkbox
for each cbx in worksheets("Somesheetnamehere").checkboxes
msgbox cbx.name & vblf & cbx.value
next cbx
end sub

If they're checkboxes from the control toolbox toolbar placed on a worksheet:

Option Explicit
Sub testme()
Dim OLEObj as oleobject
for each oleobj in worksheets("Somesheetnamehere").oleobjects
if typeof oleobj.object is msforms.checkbox then
msgbox oleobj.name & vblf & oleobj.object.value
end if
next oleobj
end sub

If the checkbox is on a userform (designed in the VBE, not just a worksheet set
up to look like a form), the code is very close to the OLEObject code:


Option Explicit
Private Sub CommandButton1_Click()
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is msforms.CheckBox Then
MsgBox ctrl.Name & vbLf & ctrl.Value
End If
Next ctrl
End Sub

======
If you wanted to use common code for either the checkboxes from the control
toolbox toolbar (placed on a sheet) or the checkboxes on a userform, you can use
this technique from John Walkenbach:

http://spreadsheetpage.com/index.php...one_procedure/

He uses Commandbuttons in his example, but the code would be very similar.

=======
If you wanted to use common code for the checkboxes from the Forms toolbar
(placed on a worksheet), you can just assign the same macro to each of the
checkboxes.



(E-Mail Removed) wrote:
>
> I would like to create a form with a large number of checkboxes. I would
> like to be able to set their values and possibly other properties and
> retrieve their values in a look rather than have long strings of code
> reference each checkbox bt name. Is there any way to accomplish that?
>
> Thank you.


--

Dave Peterson
 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      4th Jun 2010
ps.

VBA doesn't allow you to use this kind of control array (like VB???).

Dave Peterson wrote:
>
> I think the answer is gonna depend on what kind of checkboxes these are and
> where they're located.
>
> If they're checkboxes from the Forms toolbar and they're placed on a sheet, you
> could loop through them with something like this:
>
> Option Explicit
> Sub testme()
> dim cbx as checkbox
> for each cbx in worksheets("Somesheetnamehere").checkboxes
> msgbox cbx.name & vblf & cbx.value
> next cbx
> end sub
>
> If they're checkboxes from the control toolbox toolbar placed on a worksheet:
>
> Option Explicit
> Sub testme()
> Dim OLEObj as oleobject
> for each oleobj in worksheets("Somesheetnamehere").oleobjects
> if typeof oleobj.object is msforms.checkbox then
> msgbox oleobj.name & vblf & oleobj.object.value
> end if
> next oleobj
> end sub
>
> If the checkbox is on a userform (designed in the VBE, not just a worksheet set
> up to look like a form), the code is very close to the OLEObject code:
>
> Option Explicit
> Private Sub CommandButton1_Click()
> Dim ctrl As Control
> For Each ctrl In Me.Controls
> If TypeOf ctrl Is msforms.CheckBox Then
> MsgBox ctrl.Name & vbLf & ctrl.Value
> End If
> Next ctrl
> End Sub
>
> ======
> If you wanted to use common code for either the checkboxes from the control
> toolbox toolbar (placed on a sheet) or the checkboxes on a userform, you can use
> this technique from John Walkenbach:
>
> http://spreadsheetpage.com/index.php...one_procedure/
>
> He uses Commandbuttons in his example, but the code would be very similar.
>
> =======
> If you wanted to use common code for the checkboxes from the Forms toolbar
> (placed on a worksheet), you can just assign the same macro to each of the
> checkboxes.
>
> (E-Mail Removed) wrote:
> >
> > I would like to create a form with a large number of checkboxes. I would
> > like to be able to set their values and possibly other properties and
> > retrieve their values in a look rather than have long strings of code
> > reference each checkbox bt name. Is there any way to accomplish that?
> >
> > Thank you.

>
> --
>
> Dave Peterson


--

Dave Peterson
 
Reply With Quote
 
ryguy7272
Guest
Posts: n/a
 
      4th Jun 2010
This should get you started:
http://www.youtube.com/watch?v=b3kq9PDkGKM

Look on YouTube for other, similar, videos.

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"(E-Mail Removed)" wrote:

> I would like to create a form with a large number of checkboxes. I would
> like to be able to set their values and possibly other properties and
> retrieve their values in a look rather than have long strings of code
> reference each checkbox bt name. Is there any way to accomplish that?
>
> Thank you.
> .
>

 
Reply With Quote
 
NoSpam@aol.com
Guest
Posts: n/a
 
      4th Jun 2010
Thanks - That will work great!

On Fri, 04 Jun 2010 17:34:57 -0500, Dave Peterson
<(E-Mail Removed)> wrote:


>If the checkbox is on a userform (designed in the VBE, not just a worksheet set
>up to look like a form), the code is very close to the OLEObject code:
>
>
>Option Explicit
>Private Sub CommandButton1_Click()
>Dim ctrl As Control
>For Each ctrl In Me.Controls
> If TypeOf ctrl Is msforms.CheckBox Then
> MsgBox ctrl.Name & vbLf & ctrl.Value
> End If
>Next ctrl
>End Sub


>(E-Mail Removed) wrote:
>>
>> I would like to create a form with a large number of checkboxes. I would
>> like to be able to set their values and possibly other properties and
>> retrieve their values in a look rather than have long strings of code
>> reference each checkbox bt name. Is there any way to accomplish that?
>>
>> Thank you.


 
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
Jagged Arrays Problem - How to Assign Arrays to an Array Zigs Microsoft Excel Programming 3 11th Apr 2007 01:39 AM
Losing data in controls (and arrays) during unhandled exceptions. David Microsoft Excel Programming 4 6th Dec 2006 07:17 PM
Creating and Referencing Arrays of Web controls Al Wilkerson Microsoft Dot NET 0 8th Jan 2006 12:30 AM
Passing Arrays In & Out of Custom Controls? =?Utf-8?B?Q3JhaWdMZWFybmluZ0NTaGFycA==?= Microsoft Dot NET 1 10th Aug 2005 10:47 PM
Arrays of Controls news Microsoft ASP .NET 4 9th Aug 2004 05:33 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:56 AM.