Reducing Code

  • Thread starter Thread starter Garry Jones
  • Start date Start date
G

Garry Jones

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
 
For exit and beforeupdate, you would need to duplicate it for each textbox.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top