ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Objects and Variables (https://www.excelbanter.com/excel-programming/296530-objects-variables.html)

Geoff H

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

Bob Phillips[_6_]

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





All times are GMT +1. The time now is 04:40 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com