Method with textbox as argument

  • Thread starter Thread starter mad
  • Start date Start date
M

mad

Can we make a method with a textbox as an argument, like:

public sub ModifyTextBox(theTextBox as TextBox)

End sub

VBA does seem to accept this, but then, how do I pass the argument

ModifyTextBox(...)

Thanks

Michel
 
mad said:
Can we make a method with a textbox as an argument, like:

public sub ModifyTextBox(theTextBox as TextBox)

End sub

VBA does seem to accept this, but then, how do I pass the argument

ModifyTextBox(...)

Thanks

Michel

Sure, you can do that. From an event procedure on a form, you might
write either

Call ModifyTextBox(Me!MyTextBox)

or

ModifyTextBox Me!MyTextBox

However, you must not write

ModifyTextBox (Me!MyTextBox)

because that will be interpreted as a request for VBA to evaluate the
textbox and pass its value to the procedure, which will naturally result
in a type mismatch error.
 
Back
Top