Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass control/activecontrol to procedure/function

Status
Not open for further replies.

fishysheep

Programmer
Joined
Oct 13, 2001
Messages
54
Location
GB
Hi

This should be so easy but it's got me banging my head against the wall. I need to pass in the name of a control to a procedure. I've tried

// call proc - I've tried all the following, the call
// is from the click event of the text box.
whatever activecontrol
call whatever(activecontrol)
whatever txtA

private sub whatever(t as textbox)
msgbox t.name
end sub

I either get type mismatch errors in the call or invalid oject in the whatever proc.


Mike
 
First of all you have to declare the function parameter as ByRef. Example :

private sub whatever(byref t as textbox)
msgbox t.name
end sub

Then you call the function as usual:

Whatever ActiveControl
or
Call Whatever(ActiveControl)

Remember: if the parameter is declared Byval, you pass the value to the function. If it is declared Byref, you pass a reference of the object to the function (you pass the object).

I hope this would solve your problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top