PC Review


Reply
Thread Tools Rate Thread

Check Box checking

 
 
Steve
Guest
Posts: n/a
 
      30th May 2008
Hi

I have 12 check boxes for each month.

Is there a quick way of looping through all the check boxes to see if they
are ticked or not?

I then want to write the info to an array.

Thanks

Steve
 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      30th May 2008
You want to know what? Which ones are checked, how many are checked, if any
at all are checked, if none are checked. Pick one.

"Steve" wrote:

> Hi
>
> I have 12 check boxes for each month.
>
> Is there a quick way of looping through all the check boxes to see if they
> are ticked or not?
>
> I then want to write the info to an array.
>
> Thanks
>
> Steve

 
Reply With Quote
 
Steve
Guest
Posts: n/a
 
      30th May 2008
Which ones are checked

"JLGWhiz" wrote:

> You want to know what? Which ones are checked, how many are checked, if any
> at all are checked, if none are checked. Pick one.
>
> "Steve" wrote:
>
> > Hi
> >
> > I have 12 check boxes for each month.
> >
> > Is there a quick way of looping through all the check boxes to see if they
> > are ticked or not?
> >
> > I then want to write the info to an array.
> >
> > Thanks
> >
> > Steve

 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      30th May 2008
Where are the CheckBoxes at... directly on the worksheet or on a UserForm?
If on the worksheet, where did they come from... the Forms Toolbar or the
Visual Basic toolbar?

Rick


"Steve" <(E-Mail Removed)> wrote in message
news:E7A4FFF2-536E-4C04-A3DF-(E-Mail Removed)...
> Hi
>
> I have 12 check boxes for each month.
>
> Is there a quick way of looping through all the check boxes to see if they
> are ticked or not?
>
> I then want to write the info to an array.
>
> Thanks
>
> Steve


 
Reply With Quote
 
Steve
Guest
Posts: n/a
 
      30th May 2008
Apologies

They are on a user form

"Rick Rothstein (MVP - VB)" wrote:

> Where are the CheckBoxes at... directly on the worksheet or on a UserForm?
> If on the worksheet, where did they come from... the Forms Toolbar or the
> Visual Basic toolbar?
>
> Rick
>
>
> "Steve" <(E-Mail Removed)> wrote in message
> news:E7A4FFF2-536E-4C04-A3DF-(E-Mail Removed)...
> > Hi
> >
> > I have 12 check boxes for each month.
> >
> > Is there a quick way of looping through all the check boxes to see if they
> > are ticked or not?
> >
> > I then want to write the info to an array.
> >
> > Thanks
> >
> > Steve

>
>

 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      30th May 2008
Something like this maybe (using a CommandButton to enact the code for
example purposes only)...

Private Sub CommandButton1_Click()
Dim Cnt As Long
Dim Ctrl As Control
Dim ChkBxArray() As String
ReDim ChkBxArray(1 To 12)
For Each Ctrl In Me.Controls
If TypeOf Ctrl Is MSForms.CheckBox Then
If Ctrl.Value Then
Cnt = Cnt + 1
ChkBxArray(Cnt) = Ctrl.Name
End If
End If
Next
ReDim Preserve ChkBxArray(1 To Cnt)
' Prove it worked
For Cnt = 1 To UBound(ChkBxArray)
Debug.Print ChkBxArray(Cnt)
Next
End Sub

Rick


"Steve" <(E-Mail Removed)> wrote in message
news:5F4A97BD-AF4E-45EA-891F-(E-Mail Removed)...
> Apologies
>
> They are on a user form
>
> "Rick Rothstein (MVP - VB)" wrote:
>
>> Where are the CheckBoxes at... directly on the worksheet or on a
>> UserForm?
>> If on the worksheet, where did they come from... the Forms Toolbar or the
>> Visual Basic toolbar?
>>
>> Rick
>>
>>
>> "Steve" <(E-Mail Removed)> wrote in message
>> news:E7A4FFF2-536E-4C04-A3DF-(E-Mail Removed)...
>> > Hi
>> >
>> > I have 12 check boxes for each month.
>> >
>> > Is there a quick way of looping through all the check boxes to see if
>> > they
>> > are ticked or not?
>> >
>> > I then want to write the info to an array.
>> >
>> > Thanks
>> >
>> > Steve

>>
>>


 
Reply With Quote
 
Norman Jones
Guest
Posts: n/a
 
      30th May 2008
Hi Steve,

Try something like:


'==========>>
Option Explicit
Dim arr(1 To 12) As Boolean

'------------>>
Private Sub CommandButton1_Click()
Dim Ctrl As msforms.Control
Dim i As Long

For Each Ctrl In Me.Controls
With Ctrl
If TypeOf Ctrl Is msforms.CheckBox Then
i = i + 1
arr(i) = .Value
End If
End With
Next Ctrl

End Sub

'------------>>
Private Sub CommandButton2_Click()
MsgBox arr(1)
End Sub
'<<==========



---
Regards.
Norman


"Steve" <(E-Mail Removed)> wrote in message
news:E7A4FFF2-536E-4C04-A3DF-(E-Mail Removed)...
> Hi
>
> I have 12 check boxes for each month.
>
> Is there a quick way of looping through all the check boxes to see if they
> are ticked or not?
>
> I then want to write the info to an array.
>
> Thanks
>
> Steve


 
Reply With Quote
 
Steve
Guest
Posts: n/a
 
      31st May 2008
Many Thanks Rick

I'll give it a go

Steve

"Rick Rothstein (MVP - VB)" wrote:

> Something like this maybe (using a CommandButton to enact the code for
> example purposes only)...
>
> Private Sub CommandButton1_Click()
> Dim Cnt As Long
> Dim Ctrl As Control
> Dim ChkBxArray() As String
> ReDim ChkBxArray(1 To 12)
> For Each Ctrl In Me.Controls
> If TypeOf Ctrl Is MSForms.CheckBox Then
> If Ctrl.Value Then
> Cnt = Cnt + 1
> ChkBxArray(Cnt) = Ctrl.Name
> End If
> End If
> Next
> ReDim Preserve ChkBxArray(1 To Cnt)
> ' Prove it worked
> For Cnt = 1 To UBound(ChkBxArray)
> Debug.Print ChkBxArray(Cnt)
> Next
> End Sub
>
> Rick
>
>
> "Steve" <(E-Mail Removed)> wrote in message
> news:5F4A97BD-AF4E-45EA-891F-(E-Mail Removed)...
> > Apologies
> >
> > They are on a user form
> >
> > "Rick Rothstein (MVP - VB)" wrote:
> >
> >> Where are the CheckBoxes at... directly on the worksheet or on a
> >> UserForm?
> >> If on the worksheet, where did they come from... the Forms Toolbar or the
> >> Visual Basic toolbar?
> >>
> >> Rick
> >>
> >>
> >> "Steve" <(E-Mail Removed)> wrote in message
> >> news:E7A4FFF2-536E-4C04-A3DF-(E-Mail Removed)...
> >> > Hi
> >> >
> >> > I have 12 check boxes for each month.
> >> >
> >> > Is there a quick way of looping through all the check boxes to see if
> >> > they
> >> > are ticked or not?
> >> >
> >> > I then want to write the info to an array.
> >> >
> >> > Thanks
> >> >
> >> > Steve
> >>
> >>

>
>

 
Reply With Quote
 
Steve
Guest
Posts: n/a
 
      31st May 2008
Many Thanks Norman

I'll give it a go.

Appreciate your time.

regards

Steve

"Norman Jones" wrote:

> Hi Steve,
>
> Try something like:
>
>
> '==========>>
> Option Explicit
> Dim arr(1 To 12) As Boolean
>
> '------------>>
> Private Sub CommandButton1_Click()
> Dim Ctrl As msforms.Control
> Dim i As Long
>
> For Each Ctrl In Me.Controls
> With Ctrl
> If TypeOf Ctrl Is msforms.CheckBox Then
> i = i + 1
> arr(i) = .Value
> End If
> End With
> Next Ctrl
>
> End Sub
>
> '------------>>
> Private Sub CommandButton2_Click()
> MsgBox arr(1)
> End Sub
> '<<==========
>
>
>
> ---
> Regards.
> Norman
>
>
> "Steve" <(E-Mail Removed)> wrote in message
> news:E7A4FFF2-536E-4C04-A3DF-(E-Mail Removed)...
> > Hi
> >
> > I have 12 check boxes for each month.
> >
> > Is there a quick way of looping through all the check boxes to see if they
> > are ticked or not?
> >
> > I then want to write the info to an array.
> >
> > Thanks
> >
> > Steve

>

 
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
Checking the Value of a Check Box in a Macro ScottL Microsoft Excel Programming 0 11th Feb 2010 09:04 PM
Data Check not checking =?Utf-8?B?VG9kZCBLLg==?= Microsoft Access Form Coding 14 14th Feb 2007 09:04 PM
Re: checking a check box from a report? fredg Microsoft Access Reports 0 19th Jan 2007 10:32 PM
Checking value of a check box on a report Tim Microsoft Access Reports 2 16th Apr 2004 04:27 PM
Checking a check box without using the mouse Cy Windows XP Internet Explorer 2 9th Nov 2003 06:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:43 PM.