Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Reducing Code

I have hundreds of text boxes on a user form.

For each text box I need to run the following traps on Exit and
BeforeUpdate to check user input and reset to old input if new input
does not meet requirements. I know I can run these traps as private
subs. By returning True or False I can trap the user or allow user to
continue inputting in the next text box.

The following works..
________

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Cancel = Chkinp(TextBox1)
End Sub
_________

________

Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
Cancel = Chkinp(TextBox1)
End Sub
________

My question...

Must I duplicate the code for every TextBox? Or is a way to use "For
Each", a variable or something? If this code exists where would I put
this so it would be valid for the entire user form. (ie without creating
two new Private Subs for every text box).

Another thought, can I run this code on "active text box", would that
solve this the same way?

Garry Jones
Sweden

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Reducing Code

For exit and beforeupdate, you would need to duplicate it for each textbox.

--
Regards,
Tom Ogilvy

"Garry Jones" wrote in message
...
I have hundreds of text boxes on a user form.

For each text box I need to run the following traps on Exit and
BeforeUpdate to check user input and reset to old input if new input
does not meet requirements. I know I can run these traps as private
subs. By returning True or False I can trap the user or allow user to
continue inputting in the next text box.

The following works..
________

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Cancel = Chkinp(TextBox1)
End Sub
_________

________

Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
Cancel = Chkinp(TextBox1)
End Sub
________

My question...

Must I duplicate the code for every TextBox? Or is a way to use "For
Each", a variable or something? If this code exists where would I put
this so it would be valid for the entire user form. (ie without creating
two new Private Subs for every text box).

Another thought, can I run this code on "active text box", would that
solve this the same way?

Garry Jones
Sweden



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
Reducing the size. MFS Excel Discussion (Misc queries) 5 August 22nd 09 05:12 AM
Reducing balance [email protected] Excel Discussion (Misc queries) 3 March 9th 09 08:20 AM
Reducing decimal places mcgrape Excel Discussion (Misc queries) 4 July 16th 08 08:00 PM
Reducing Spreadsheet motel112 Excel Discussion (Misc queries) 1 April 15th 08 11:48 PM
help reducing lines of code Robert Christie Excel Programming 3 September 14th 03 02:12 PM


All times are GMT +1. The time now is 02:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"