Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Objects and Variables

I have problem that bugs the hell out of me.

Is there some way of accessing an object by a variable name? ie
instead of
frmMain.cbParts1.value up to frmMain.cbParts10.value

use a variable to give

frmMain.("cbParts" & iCount).value

to loop through them. I have tried using the Controls but it
sometimes results in the controls out of sequence so that I address

cbParts7
cbParts1
cbParts2
cbParts3
cbParts4
cbParts5
cbParts6
cbParts10
cbParts8
cbParts9

which when filling in a form isnt that great.

Is there any way to use a variable in an objects name?

Thanks in advance

Geoff
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Objects and Variables

Hi Geoff,

Here is an example that loops through the controls collection of a userform,
and checks for a checkbox

Dim ctl As msforms.Control

For Each ctl In Me.Controls
If TypeName(ctl) = "CheckBox" Then
Debug.Print ctl.Caption
End If
Next ctl


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Geoff H" wrote in message
om...
I have problem that bugs the hell out of me.

Is there some way of accessing an object by a variable name? ie
instead of
frmMain.cbParts1.value up to frmMain.cbParts10.value

use a variable to give

frmMain.("cbParts" & iCount).value

to loop through them. I have tried using the Controls but it
sometimes results in the controls out of sequence so that I address

cbParts7
cbParts1
cbParts2
cbParts3
cbParts4
cbParts5
cbParts6
cbParts10
cbParts8
cbParts9

which when filling in a form isnt that great.

Is there any way to use a variable in an objects name?

Thanks in advance

Geoff



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
Not at all clear on use of variables and/or object variables JMay-Rke Excel Discussion (Misc queries) 11 July 4th 08 06:36 PM
OLE Objects [email protected] Excel Discussion (Misc queries) 0 March 7th 08 09:44 PM
VBA Objects Kevin Excel Discussion (Misc queries) 8 January 1st 05 09:07 PM
Objects and Variables Geoff H Excel Programming 4 January 3rd 04 04:08 PM
Changing objects on other Worksheets with Variables Dave Baranas Excel Programming 3 August 10th 03 07:29 PM


All times are GMT +1. The time now is 01:55 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"