Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Referencing form controls with a loop

I have a form that has 12 identical lines (same label, button, field
etc.).

In normal VB, I can create each control as an array, ex.
frmMyForm.lblMyLabel(1).
So this works great for changing something for all the controls with a
loop:

For Myloop = 1 to 12
frmMyForm.btnMyButton(MyLoop).Enabled = False
Next MyLoop

In VBA, I have to independently name each control and reference them
each one by one:

frmMyForm.btnMybutton1.Enabled = False
frmMyForm.btnMybutton2.Enabled = False
...
frmMyForm.btnMybutton12.Enabled = False

Does anyone have a shortcut to reference multiple identical controls
with a loop in VBA?!

Thanks.

John

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,388
Default Referencing form controls with a loop

Try referring to the control on the form as frmWhatEver.control(x) where x is
and integer reference to the controls... you will have to figure a way to
find the buttons by referring to the name of control eg.
left(frmWhatEver.control(x).name , 3) = "btn" or something like that - don't
know if there is a way to see what the control typeis ..

Best



"robotman" wrote:

I have a form that has 12 identical lines (same label, button, field
etc.).

In normal VB, I can create each control as an array, ex.
frmMyForm.lblMyLabel(1).
So this works great for changing something for all the controls with a
loop:

For Myloop = 1 to 12
frmMyForm.btnMyButton(MyLoop).Enabled = False
Next MyLoop

In VBA, I have to independently name each control and reference them
each one by one:

frmMyForm.btnMybutton1.Enabled = False
frmMyForm.btnMybutton2.Enabled = False
...
frmMyForm.btnMybutton12.Enabled = False

Does anyone have a shortcut to reference multiple identical controls
with a loop in VBA?!

Thanks.

John


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Referencing form controls with a loop

I'm not sure what you mean, but each type of control on a UserForm has an
index number that can be used in an array. Any collection can be used in an
array in VBA and controls are collections.

"robotman" wrote:

I have a form that has 12 identical lines (same label, button, field
etc.).

In normal VB, I can create each control as an array, ex.
frmMyForm.lblMyLabel(1).
So this works great for changing something for all the controls with a
loop:

For Myloop = 1 to 12
frmMyForm.btnMyButton(MyLoop).Enabled = False
Next MyLoop

In VBA, I have to independently name each control and reference them
each one by one:

frmMyForm.btnMybutton1.Enabled = False
frmMyForm.btnMybutton2.Enabled = False
...
frmMyForm.btnMybutton12.Enabled = False

Does anyone have a shortcut to reference multiple identical controls
with a loop in VBA?!

Thanks.

John


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
Multipage form: Referencing controls on one page Post Tenebras Lux Excel Programming 1 August 11th 06 07:41 PM
referencing forms controls AlbertYWang Excel Programming 3 February 1st 06 01:59 PM
ActiveX Controls vs Form Controls Alex Excel Discussion (Misc queries) 1 January 11th 06 08:46 AM
Referencing worksheet controls Frederick Chow Excel Programming 2 December 12th 05 05:42 PM
Referencing to controls on a worksheet John Nikolopoulos Excel Programming 3 September 10th 03 10:08 AM


All times are GMT +1. The time now is 07:30 AM.

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"