Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi all,
In a form, there are 30 textboxes who all need the limitation of 30 chars in length. I know code can be put in the change event, but if I do it in that way, I will use 30 event handlers even I can abstract the core logic into a sub.Is there a way to use one handler for all text box controls Clara -- thank you so much for your help |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You cannot have one event handler for multiple controls.. at least not in
Excel 2003, not sure about 2007. The most you can do is put all the logic in one subroutine and call that in the individual event handlers. However, for the example that you gave, you can just set the MaxLength property of the textboxes to 30. -- Hope that helps. Vergel Adriano "clara" wrote: Hi all, In a form, there are 30 textboxes who all need the limitation of 30 chars in length. I know code can be put in the change event, but if I do it in that way, I will use 30 event handlers even I can abstract the core logic into a sub.Is there a way to use one handler for all text box controls Clara -- thank you so much for your help |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Vergel,
Thanks a lot for your help! Even the max length limitation can be done through setting the corresponding property, but for 30 textboxes it is still tedious, can you figure out a way to do it just in one time? Clara -- thank you so much for your help "Vergel Adriano" wrote: You cannot have one event handler for multiple controls.. at least not in Excel 2003, not sure about 2007. The most you can do is put all the logic in one subroutine and call that in the individual event handlers. However, for the example that you gave, you can just set the MaxLength property of the textboxes to 30. -- Hope that helps. Vergel Adriano "clara" wrote: Hi all, In a form, there are 30 textboxes who all need the limitation of 30 chars in length. I know code can be put in the change event, but if I do it in that way, I will use 30 event handlers even I can abstract the core logic into a sub.Is there a way to use one handler for all text box controls Clara -- thank you so much for your help |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Clara,
Yes, you can set the MaxLength property by code. Put this in the UserForm_Initialize sub Dim c As Control For Each c In Me.Controls If TypeOf c Is MSForms.TextBox Then c.MaxLength = 30 End If Next c -- Hope that helps. Vergel Adriano "clara" wrote: Hi Vergel, Thanks a lot for your help! Even the max length limitation can be done through setting the corresponding property, but for 30 textboxes it is still tedious, can you figure out a way to do it just in one time? Clara -- thank you so much for your help "Vergel Adriano" wrote: You cannot have one event handler for multiple controls.. at least not in Excel 2003, not sure about 2007. The most you can do is put all the logic in one subroutine and call that in the individual event handlers. However, for the example that you gave, you can just set the MaxLength property of the textboxes to 30. -- Hope that helps. Vergel Adriano "clara" wrote: Hi all, In a form, there are 30 textboxes who all need the limitation of 30 chars in length. I know code can be put in the change event, but if I do it in that way, I will use 30 event handlers even I can abstract the core logic into a sub.Is there a way to use one handler for all text box controls Clara -- thank you so much for your help |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
And also, in the Form designer, you can select all textboxes then set the
MaxLength property to 30 just one time. -- Hope that helps. Vergel Adriano "Vergel Adriano" wrote: Hi Clara, Yes, you can set the MaxLength property by code. Put this in the UserForm_Initialize sub Dim c As Control For Each c In Me.Controls If TypeOf c Is MSForms.TextBox Then c.MaxLength = 30 End If Next c -- Hope that helps. Vergel Adriano "clara" wrote: Hi Vergel, Thanks a lot for your help! Even the max length limitation can be done through setting the corresponding property, but for 30 textboxes it is still tedious, can you figure out a way to do it just in one time? Clara -- thank you so much for your help "Vergel Adriano" wrote: You cannot have one event handler for multiple controls.. at least not in Excel 2003, not sure about 2007. The most you can do is put all the logic in one subroutine and call that in the individual event handlers. However, for the example that you gave, you can just set the MaxLength property of the textboxes to 30. -- Hope that helps. Vergel Adriano "clara" wrote: Hi all, In a form, there are 30 textboxes who all need the limitation of 30 chars in length. I know code can be put in the change event, but if I do it in that way, I will use 30 event handlers even I can abstract the core logic into a sub.Is there a way to use one handler for all text box controls Clara -- thank you so much for your help |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Clara,
You can do it by defining a textbox class. This example is for buttons, but can be modified: http://www.j-walk.com/ss/excel/tips/tip44.htm hth, Doug "clara" wrote in message ... Hi all, In a form, there are 30 textboxes who all need the limitation of 30 chars in length. I know code can be put in the change event, but if I do it in that way, I will use 30 event handlers even I can abstract the core logic into a sub.Is there a way to use one handler for all text box controls Clara -- thank you so much for your help |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
event handler list | Excel Programming | |||
Event handler | Excel Programming | |||
Event handler in a cell | Excel Programming | |||
different IDispatch in event handler | Excel Programming | |||
Cell Event Handler | Excel Programming |