Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default Problem identifying with Checkbox's status

Hi

I have three checkboxes on my userform ("Userform") chk1, chk2, and chk3. I would like to record the name(s) of the checked checkbox(es) in a dynamic array ("MyArray")

For some reason my current code below doesn't recognise that the checkbox has been checked. It is also interesting to note that the ".Value" method for ctrlDummy does not show up when typing the code...maybe this could be the reason

Could you please help me fix this error

----------------------------------------------------------
Sub ChkBox(

Dim ctrlDummy As msforms.Contro
Dim MyArray() As String
Dim i as Intege

For Each ctrlDummy In Userform.Control

If TypeOf ctrlDummy Is msforms.CheckBox The

If ctrlDummy.Value The

MyArray(i) = ctrlDummy.Nam

i = i +

End I

End I

Next ctrlDumm

ReDim MyArray(i

End Su
----------------------------------------------------------

Thanks very much for your help

SuperJas.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 218
Default Problem identifying with Checkbox's status

Sub ChkBox()
Dim ctrlDummy As MSForms.Control
Dim MyArray() As String
Dim i As Integer, ii As Integer
i = 0
For Each ctrlDummy In UserForm.Controls
If TypeOf ctrlDummy Is MSForms.CheckBox Then
If ctrlDummy.Value = True Then
ReDim Preserve MyArray(i)
MyArray(i) = ctrlDummy.Name
i = i + 1
End If
End If
Next ctrlDummy

For ii = 0 To i - 1
MsgBox MyArray(ii)
Next

End Sub


Regards,
Greg

-----Original Message-----
Hi,

I have three checkboxes on my userform ("Userform") chk1,

chk2, and chk3. I would like to record the name(s) of the
checked checkbox(es) in a dynamic array ("MyArray").

For some reason my current code below doesn't recognise

that the checkbox has been checked. It is also interesting
to note that the ".Value" method for ctrlDummy does not
show up when typing the code...maybe this could be the
reason?


Could you please help me fix this error?

----------------------------------------------------------

-
Sub ChkBox()


Dim ctrlDummy As msforms.Control
Dim MyArray() As String
Dim i as Integer


For Each ctrlDummy In Userform.Controls

If TypeOf ctrlDummy Is msforms.CheckBox

Then

If ctrlDummy.Value Then

MyArray(i) = ctrlDummy.Name

i = i + 1

End If

End If

Next ctrlDummy


ReDim MyArray(i)


End Sub
----------------------------------------------------------

-


Thanks very much for your help,

SuperJas.
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default Problem identifying with Checkbox's status

Hi Greg

Thanks for your suggestion. Unfortunately it still fails to recognise the checkbox is checked

I'm thinking that it's because the ctrlDummy doesn't have a Value method, and hence the ctrlDummy.Value isn't actually going to the checkbox's value

So to get around this, is it possible to create another variable like so

--------------------------------
Dim chkDummy as MSForms.Checkbo
--------------------------------

and then set the chkDummy to the ctrlDummy checkbox

I was thinking along the lines of

----------------------------------------------------
For Each ctrlDummy In Userform.Control

If TypeOf ctrlDummy Is MSForms.CheckBox The

****Set chkDummy = CtrlDummy***

If chkDummy.Value = True The
ReDim Preserve MyArray(i
MyArray(i) = chkDummy.Nam
i = i +
End I

End I

Next ctrlDumm
----------------------------------------------------

The "****" line is causing errors. What would be the correct code to achieve this

Thanks very much

SuperJas.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 218
Default Problem identifying with Checkbox's status

Hi SuperJas,

The code I posted worked for me when run from a userform
assigned to the userform Click event. I don't know how
you're executing the code. It might be a version
dependent issue - i.e. MSForms.Checkbox may not be
recognized. I suggest using the TypeName function
instead. The following code worked for me when assigned
to a command button used to close the userform:

Private Sub CommandButton1_Click()
Dim ctrlDummy As Control
Dim MyArray() As String
Dim i As Integer, ii As Integer
i = 0
For Each ctrlDummy In Me.Controls
If TypeName(ctrlDummy) = "CheckBox" Then
If ctrlDummy.Value = True Then
ReDim Preserve MyArray(i)
MyArray(i) = ctrlDummy.Name
i = i + 1
End If
End If
Next ctrlDummy
For ii = 0 To i - 1
MsgBox MyArray(ii)
Next
Unload Me
End Sub

Regards,
Greg

-----Original Message-----
Hi Greg,

Thanks for your suggestion. Unfortunately it still fails

to recognise the checkbox is checked.

I'm thinking that it's because the ctrlDummy doesn't have

a Value method, and hence the ctrlDummy.Value isn't
actually going to the checkbox's value?

So to get around this, is it possible to create another

variable like so:

---------------------------------
Dim chkDummy as MSForms.Checkbox
---------------------------------

and then set the chkDummy to the ctrlDummy checkbox?

I was thinking along the lines of:


-----------------------------------------------------
For Each ctrlDummy In Userform.Controls

If TypeOf ctrlDummy Is MSForms.CheckBox Then

****Set chkDummy = CtrlDummy****

If chkDummy.Value = True Then
ReDim Preserve MyArray(i)
MyArray(i) = chkDummy.Name
i = i + 1
End If

End If

Next ctrlDummy
-----------------------------------------------------

The "****" line is causing errors. What would be the

correct code to achieve this?

Thanks very much,

SuperJas.
.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default Problem identifying with Checkbox's status

Hi Greg

I've found the problem with the checkboxes - I unloaded the userform *before* assigning values to my array. So that's all fixed now. =

Thanks heaps for your help! Very much appreciated

SuperJas.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with test to columns feature identifying odd delimiting character mark_jm via OfficeKB.com Excel Discussion (Misc queries) 4 May 4th 10 11:22 AM
Status Bar box problem Old Keith Excel Worksheet Functions 4 July 13th 07 10:36 PM
Problem getting a msoButtonDown status [email protected] Excel Programming 0 November 17th 03 12:23 AM
looping through all checkbox's in a userform strataguru[_3_] Excel Programming 1 October 7th 03 05:01 PM
declaring an array of CheckBox's Didier Poskin Excel Programming 4 September 9th 03 09:02 AM


All times are GMT +1. The time now is 06:39 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"