RE: design one event handler for multiple textboxes



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
.



Relevant Pages

  • Re: Jump to next textbox upon character entering
    ... First of all set the MaxLength property to 1 ... if you want to move to the next control after one character is ... > I have a series of textboxes and each of them can contain one letter only. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Really easy question about looping through controls
    ... Here's an example of how to loop through all the controls on a form. ... This example adds event handlers to all the textboxes and comboboxes so when the user tabs into them, or tabs out of them, it handles the event. ... Private Sub AddEventHandlers(ByVal ctrlContainer As Control) ...
    (microsoft.public.dotnet.languages.vb.controls)
  • Re: Really easy question about looping through controls
    ... Private Sub AddEventHandlers(ByVal ctrlContainer As Control) ... Instead of adding event handlers, you can check the tag or name or whatever ... I want to loop through those nine textboxes, ... dim arMatrixas Byte ...
    (microsoft.public.dotnet.languages.vb.controls)
  • Re: Really easy question about looping through controls
    ... So I can't specify which controls on a form to loop through? ... Private Sub AddEventHandlers(ByVal ctrlContainer As Control) ... Instead of adding event handlers, you can check the tag or name or whatever ... I want to loop through those nine textboxes, ...
    (microsoft.public.dotnet.languages.vb.controls)
  • Edanmo Richedit control
    ... I have the MaxLength property set to 0. ... My problem occurs when there are 65537 characters displayed. ... the control refuses to accept any more text. ... the control refuses to display any more characters. ...
    (microsoft.public.vb.general.discussion)