Method with textbox as argument

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
 
D

Dirk Goldgar

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.
 

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

Top