By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,107 Members | 1,323 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,107 IT Pros & Developers. It's quick & easy.

Referring to Multiple Controls... easily

100+
P: 365
Hello all, just i have a form with a lot of controls on it and wondered if there was an easy way to refer to them... they have sequencial numbers ie

cmb01,cmb02,cmb03......cmb42 what i want to do is set the on click event to a custom function ive hoped it would be simple but this code doesnt work.


Expand|Select|Wrap|Line Numbers
  1. Dim ctlcmb as control, cmbNum as byte
  2. for cmbNum = 1 to 42
  3.       Me.cmb & bytindex & .OnClick = "=txtDayBlock(" & cmbNum & ")"
  4. next
  5.  
if i can crack this i can use it else where (hopefully)

Thanks, Dan
Jan 13 '09 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 1,287
You can refer to controls like

Expand|Select|Wrap|Line Numbers
  1.  
  2. Me.Controls("cmb" & cmbNum).Caption
  3.  
I haven't used that for assigning functions to events though.

Note that you may want to change the names of your controls to eg. cmb01 to cmb1 for this to work.

Hope that helps :)
Jan 13 '09 #2

100+
P: 365
thanks for the quick reply and it works, genius!!

did have a problem with the cmb01 so i was lazy and used a shortcut

Expand|Select|Wrap|Line Numbers
  1. cmbName = "cmb"
  2. If cmbNum <10 then cmbName = cmbName & 0
  3. Me.Controls(cmbName & cmbNum).OnDblClick = "=Function(" & cmbNum & ")" 
Thanks again

Dan
Jan 13 '09 #3

NeoPa
Expert Mod 15k+
P: 31,419
...or you can say :
Expand|Select|Wrap|Line Numbers
  1. Me.Controls(cmbName & Format(cmbNum, "00")).OnDblClick = "=Function(" & cmbNum & ")"
Jan 14 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.