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

Hi
Can anyone help me with a little problem. I wish to access a number of
objects (eg textboxes or check boxes) using a "for Next "loop with a
variable instead of how it is now

cbPart1.Value = ""
txtDesc1.Value = ""
txtLoc1.Value = ""
txtUsed1.Value = ""
txtLeft1.Value = ""

cbPart2.Value = ""
txtDesc2.Value = ""
txtLoc2.Value = ""
txtUsed2.Value = ""
txtLeft2.Value = ""

cbPart3.Value = ""
txtDesc3.Value = ""
txtLoc3.Value = ""
txtUsed3.Value = ""
txtLeft3.Value = ""

I have tried using the following and minor variations

For iCount = 1 to 10
oTemp1 = "cbPart" & (iCount)
oTemp2 = "txtDesc" & (iCount)
oTemp3 = "txtLoc" & (iCount)
oTemp4 = "txtUsed" & (iCount)
oTemp5 = "txtLeft1" & (iCount)

oTemp1.Value = ""
oTemp2.Value = ""
oTemp3.Value = ""
oTemp4.Value = ""
oTemp5.Value = ""

next

May not be the best illustration (I have one instance where I need to
test the status of 83 check boxes)but what I am after is the method or
ability to convert variables to object references as VBA doesnt seem
to support Control Arrays.

Am I flogging a dead horse?

Any help would be well helpfull (Holy Grail)
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Objects and Variables

Geoff,

Perhaps this may help:
Controls("TextBox1").Value = "hello"

Rob

"Geoff H" wrote in message
om...
Hi
Can anyone help me with a little problem. I wish to access a number of
objects (eg textboxes or check boxes) using a "for Next "loop with a
variable instead of how it is now

cbPart1.Value = ""
txtDesc1.Value = ""
txtLoc1.Value = ""
txtUsed1.Value = ""
txtLeft1.Value = ""

cbPart2.Value = ""
txtDesc2.Value = ""
txtLoc2.Value = ""
txtUsed2.Value = ""
txtLeft2.Value = ""

cbPart3.Value = ""
txtDesc3.Value = ""
txtLoc3.Value = ""
txtUsed3.Value = ""
txtLeft3.Value = ""

I have tried using the following and minor variations

For iCount = 1 to 10
oTemp1 = "cbPart" & (iCount)
oTemp2 = "txtDesc" & (iCount)
oTemp3 = "txtLoc" & (iCount)
oTemp4 = "txtUsed" & (iCount)
oTemp5 = "txtLeft1" & (iCount)

oTemp1.Value = ""
oTemp2.Value = ""
oTemp3.Value = ""
oTemp4.Value = ""
oTemp5.Value = ""

next

May not be the best illustration (I have one instance where I need to
test the status of 83 check boxes)but what I am after is the method or
ability to convert variables to object references as VBA doesnt seem
to support Control Arrays.

Am I flogging a dead horse?

Any help would be well helpfull (Holy Grail)



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

Geoff,

Access these controls through the controls collection. For example

For iCount = 1 to 10
oTemp1 = Controls("cbPart" & (iCount))
oTemp2 = Controls("txtDesc" & (iCount))
oTemp3 = Controls("txtLoc" & (iCount))
oTemp4 = Controls("txtUsed" & (iCount))
oTemp5 = Controls("txtLeft1" & (iCount))


--

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...
Hi
Can anyone help me with a little problem. I wish to access a number of
objects (eg textboxes or check boxes) using a "for Next "loop with a
variable instead of how it is now

cbPart1.Value = ""
txtDesc1.Value = ""
txtLoc1.Value = ""
txtUsed1.Value = ""
txtLeft1.Value = ""

cbPart2.Value = ""
txtDesc2.Value = ""
txtLoc2.Value = ""
txtUsed2.Value = ""
txtLeft2.Value = ""

cbPart3.Value = ""
txtDesc3.Value = ""
txtLoc3.Value = ""
txtUsed3.Value = ""
txtLeft3.Value = ""

I have tried using the following and minor variations

For iCount = 1 to 10
oTemp1 = "cbPart" & (iCount)
oTemp2 = "txtDesc" & (iCount)
oTemp3 = "txtLoc" & (iCount)
oTemp4 = "txtUsed" & (iCount)
oTemp5 = "txtLeft1" & (iCount)

oTemp1.Value = ""
oTemp2.Value = ""
oTemp3.Value = ""
oTemp4.Value = ""
oTemp5.Value = ""

next

May not be the best illustration (I have one instance where I need to
test the status of 83 check boxes)but what I am after is the method or
ability to convert variables to object references as VBA doesnt seem
to support Control Arrays.

Am I flogging a dead horse?

Any help would be well helpfull (Holy Grail)



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Objects and Variables

Answers provided so far assume these are on a Userform. If they are on a
worksheet and from the control toolbox toolbar, you can use a similar
approach

Dim OleObj as OleObject
varr = Array("cbPart","txtDesc","txtLoc","txtUsed","txtLe ft")

for i = 1 to 83
for j = lbound(varr) to ubound(varr)
set OleObj = ActiveSheet.OleObjects(varr(j) & i)
if typeof OleObj.Object is MSForms.Textbox then
OleObj.Object.Value = ""
elseif typeof OleObj.Object is MsForms.Checkbox then
OleObj.Object.Value = False
end if
next j
next i

--
Regards,
Tom Ogilvy


Geoff H wrote in message
om...
Hi
Can anyone help me with a little problem. I wish to access a number of
objects (eg textboxes or check boxes) using a "for Next "loop with a
variable instead of how it is now

cbPart1.Value = ""
txtDesc1.Value = ""
txtLoc1.Value = ""
txtUsed1.Value = ""
txtLeft1.Value = ""

cbPart2.Value = ""
txtDesc2.Value = ""
txtLoc2.Value = ""
txtUsed2.Value = ""
txtLeft2.Value = ""

cbPart3.Value = ""
txtDesc3.Value = ""
txtLoc3.Value = ""
txtUsed3.Value = ""
txtLeft3.Value = ""

I have tried using the following and minor variations

For iCount = 1 to 10
oTemp1 = "cbPart" & (iCount)
oTemp2 = "txtDesc" & (iCount)
oTemp3 = "txtLoc" & (iCount)
oTemp4 = "txtUsed" & (iCount)
oTemp5 = "txtLeft1" & (iCount)

oTemp1.Value = ""
oTemp2.Value = ""
oTemp3.Value = ""
oTemp4.Value = ""
oTemp5.Value = ""

next

May not be the best illustration (I have one instance where I need to
test the status of 83 check boxes)but what I am after is the method or
ability to convert variables to object references as VBA doesnt seem
to support Control Arrays.

Am I flogging a dead horse?

Any help would be well helpfull (Holy Grail)



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 575
Default Objects and Variables

Geoff,

You want something like

For nCounter = 0 to 10
msgbox frmMyForm.Controls("txt" & cstr(nCounter)).Text
msgbox frmMyForm.Controls("chk" & cstr(nCounter)).Value
Next nCounter

where your text boxes are obviously txt1, txt2, checkboxes chk1, chk2 etc

Robin Hammond
www.enhanceddatasystems.com


"Geoff H" wrote in message
om...
Hi
Can anyone help me with a little problem. I wish to access a number of
objects (eg textboxes or check boxes) using a "for Next "loop with a
variable instead of how it is now

cbPart1.Value = ""
txtDesc1.Value = ""
txtLoc1.Value = ""
txtUsed1.Value = ""
txtLeft1.Value = ""

cbPart2.Value = ""
txtDesc2.Value = ""
txtLoc2.Value = ""
txtUsed2.Value = ""
txtLeft2.Value = ""

cbPart3.Value = ""
txtDesc3.Value = ""
txtLoc3.Value = ""
txtUsed3.Value = ""
txtLeft3.Value = ""

I have tried using the following and minor variations

For iCount = 1 to 10
oTemp1 = "cbPart" & (iCount)
oTemp2 = "txtDesc" & (iCount)
oTemp3 = "txtLoc" & (iCount)
oTemp4 = "txtUsed" & (iCount)
oTemp5 = "txtLeft1" & (iCount)

oTemp1.Value = ""
oTemp2.Value = ""
oTemp3.Value = ""
oTemp4.Value = ""
oTemp5.Value = ""

next

May not be the best illustration (I have one instance where I need to
test the status of 83 check boxes)but what I am after is the method or
ability to convert variables to object references as VBA doesnt seem
to support Control Arrays.

Am I flogging a dead horse?

Any help would be well helpfull (Holy Grail)



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
displaying objects Soccerboy83 Excel Discussion (Misc queries) 3 September 17th 09 01:18 AM
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
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:05 PM.

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

About Us

"It's about Microsoft Excel"