Many TextBoxes - One Event

  • Thread starter Thread starter marwan
  • Start date Start date
M

marwan

I have many TextBoxes in my form (about 14 TextBox)
I want all of them to behave in the same manner in the "BeforeUpdate"
event.
Is there any method to unify the code of the Event procedure, rather
than repeating it for every TextBox I have?
I know this is possible through class modules, but how?
Thanks
 
Create a sub in the form's module (same place as the event code) and call it
whatever you want:
Private Sub DoStuffForTextBoxes
... put the code you want run here
End Sub

then in the before update event just say:
DoStuffForTextBoxes
and it will call your procedure.
If you need to send a value to the procedure, you can do that as well:
Check out the help on passing an argument to a function or subroutine.
 
marwan said:
I have many TextBoxes in my form (about 14 TextBox)
I want all of them to behave in the same manner in the "BeforeUpdate"
event.
Is there any method to unify the code of the Event procedure, rather
than repeating it for every TextBox I have?
I know this is possible through class modules, but how?


You don't actually need a BeforeUpdate procedure for each
text box. Instead you can call your function by using
=Functionname()
in each of the text box's Before Update **property**

If the function needs to "know" which text boxes the
function is operating on, it can refer to it by using:
Me.ActiveControl
 
Back
Top