Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Enumerate form items

How can I enumerate form items so that I can, say, change BackColor,
checkbox status, etc. in a loop?

or, as an alternative, if I generate the object name ("form1.cb1",
"form1.cb2", etc) as a string, how can I refer to it using the string?

Thanks,

....kurt


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Enumerate form items


Dim ctl As Control

For Each ctl In Me.Controls
Select Case TypeName(ctl)
Case "CheckBox": MsgBox "checkbox " & ctl.Name
Case "CommandButton": MsgBox "Button " & ctl.Name
End Select
Next ctl


--
HTH

Bob Phillips

"Kurt" wrote in message
...
How can I enumerate form items so that I can, say, change BackColor,
checkbox status, etc. in a loop?

or, as an alternative, if I generate the object name ("form1.cb1",
"form1.cb2", etc) as a string, how can I refer to it using the string?

Thanks,

...kurt




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Enumerate form items

for i = 1 to 2
set cbx = form1.controls("cb" & i)
Next


or
sStr = "cb1"

set cbx = form1.Controls(sStr)
--
Regards,
Tom Ogilvy


"Kurt" wrote in message
...
How can I enumerate form items so that I can, say, change BackColor,
checkbox status, etc. in a loop?

or, as an alternative, if I generate the object name ("form1.cb1",
"form1.cb2", etc) as a string, how can I refer to it using the string?

Thanks,

...kurt




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 121
Default Enumerate form items

Is this a userform, or a worksheet? I have written routines which loop
through control objects on userforms as follows:

Dim ctrl as Control
For Each ctrl In Me.Controls
If ctrl.Tag = "SpecialItem" Then

'Do things to all items I have set the Tag property a certain
way for (i.e., = 'SpecialItem' or whatever)
End if
'OR
If LCASE(left(ctrl.Name,3)) = "ckb" then
'Do things to items I have named with prefix 'ckb'
End If
'OR
If TypeName(ctrl) = "CheckBox" then
'Do things to all checkboxes
End if
Next ctrl


Note: The second item - testing the name - does not work if you created the
control dynamically as a control array,
such as
Dim chk(1 to 3) As Control
Set chk(1) = Controls.Add("Forms.CheckBox.1", True)
Set chk(2) = Controls.Add("Forms.CheckBox.1", True)
Set chk(3) = Controls.Add("Forms.CheckBox.1", True)

because the name property for each will just be "-1"
"Kurt" wrote in message
...
How can I enumerate form items so that I can, say, change BackColor,
checkbox status, etc. in a loop?

or, as an alternative, if I generate the object name ("form1.cb1",
"form1.cb2", etc) as a string, how can I refer to it using the string?

Thanks,

...kurt



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Enumerate form items

Thanks to all who replied. This is exactly what I was looking for. [:-)]

....kurt


"Kurt" wrote in message
...
How can I enumerate form items so that I can, say, change BackColor,
checkbox status, etc. in a loop?

or, as an alternative, if I generate the object name ("form1.cb1",
"form1.cb2", etc) as a string, how can I refer to it using the string?

Thanks,

...kurt



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
order form with multiple items and sizes for items Bernard56 Excel Discussion (Misc queries) 1 January 17th 06 11:43 PM
enumerate sheet Philippe L. Balmanno Excel Worksheet Functions 4 January 4th 06 12:41 AM
how to enumerate? tendercare New Users to Excel 3 August 1st 05 06:15 PM
2nd Form deselects list box items on main form RandyDtg1 Excel Programming 3 September 5th 04 09:32 PM
Is there any way to enumerate the cell which contain a formula? Aaron Queenan Excel Programming 1 February 12th 04 04:55 PM


All times are GMT +1. The time now is 02:00 PM.

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"