PC Review


Reply
Thread Tools Rate Thread

design one event handler for multiple textboxes

 
 
=?Utf-8?B?Y2xhcmE=?=
Guest
Posts: n/a
 
      20th Mar 2007
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 With Quote
 
 
 
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      20th Mar 2007
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

 
Reply With Quote
 
=?Utf-8?B?Y2xhcmE=?=
Guest
Posts: n/a
 
      20th Mar 2007
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

 
Reply With Quote
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      20th Mar 2007
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

 
Reply With Quote
 
Doug Glancy
Guest
Posts: n/a
 
      20th Mar 2007
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" <(E-Mail Removed)> wrote in message
news:CDDD41DD-B5FB-47A9-8104-(E-Mail Removed)...
> 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 With Quote
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      20th Mar 2007
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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ienumberable<T> / Event Handler design question... Jamie Risk Microsoft C# .NET 2 30th Mar 2007 09:07 PM
Switch to Design View without going off event handler =?Utf-8?B?Y2xhcmE=?= Microsoft Access Forms 1 16th Mar 2007 02:01 AM
Same event handler for multiple link buttons akki Microsoft ASP .NET 3 6th Feb 2006 07:22 AM
Event handler firing multiple times. schiefaw@computer.org Microsoft VB .NET 2 4th Mar 2005 06:09 PM
Multiple Event Handler Hierarchy =?Utf-8?B?U3RldmU=?= Microsoft Dot NET Framework Forms 6 23rd Aug 2004 11:23 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:42 PM.