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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Get Reference to a Control?

Status
Not open for further replies.

ubivis

Programmer
Apr 24, 2006
2
CA
I am trying to pass a control to a subroutine.
I have specified that a control is to be passed into
the method:

sub foo(ctrl as control)
.
.
.
end sub

Then:
call foo(some_control_name)

However whenever I pass a control into the method
it passes the value of the control into the method
and not the control itself. I believe VB passes by
reference but even adding byref to this does not work.

What is happening could be described in code as follows:
call foo(some_control_name.value)
but what I want is the control itself:
call foo(some_control_name)

Any suggestions?
Thanks.
 
Instead of
Code:
call foo(some_control_name)
use
Code:
foo some_control_name
The parentheses cause VB to evaluate the arguments before passing them (i.e. giving you the default property.) The other form passes the object itself.

I do note that your (presumably dummy) argument is some_control_name. If that means that you are passing the name property of the control rather than the reference to the control then you will need to change that.

[small]No! No! You're not thinking ... you're only being logical.
- Neils Bohr[/small]
 
I have found it best to be sure that I'm passing a control, rather than the value of the control. Therefore, I declare a variable as a control, then set the variable to the control that I want to pass to a routine.
[green]'Declare the variable[/green]
dim ctl as control
[green]'Set the variable to hold the control[/green]
set ctl = forms!frmSample!ctlInputField
[green]'Call the exteral routine:[/green]
ExternalRoutine ctl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top