Control Name

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a function that needs to be called many places so I want to setup a
function so I can pass the form name and control name to the function to do
some stuff. The calling form has

set_statusbartext Me.Form, Form.ActiveControl.Name

I'm trying to pass the form name and the control name to the following
function

Public Function set_statusbartext(frm As Form, ctl As Control)
Dim temp_ctr As Integer
frm.ctl.StatusBarText = ""
If frm.ctl.ListCount > 0 Then
If frm.ctl.ListCount < 15 Then
Do Until temp_ctr > frm.ctl.ListCount - 1
frm.ctl.StatusBarText = frm.ctl.StatusBarText & " [" &
frm.ctl.ItemData(temp_ctr) & "] "
temp_ctr = temp_ctr + 1
Loop
Else
frm.ctl.StatusBarText = "too many to display!"
End If
End If

End Function

the set_statusbartext function is passing the form name but the value of the
control, not the control name...what am I missing? thanks!
 
Since you are passing ctl as a control, you can get its name as:
ctl.Name

(BTW, you don't need the frm variable in this code.)
 
I don't understand... the calling form has
set_statusbartext Me.Form, Form.ActiveControl.Name
and the called function has
Public Function set_statusbartext(frm As Form, ctl As Control)
where do I put ctl.name
based on the above set_statusbartext call, it's passing the value of the
control, not it's name...what am I missing?

Allen Browne said:
Since you are passing ctl as a control, you can get its name as:
ctl.Name

(BTW, you don't need the frm variable in this code.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

PeterM said:
I have a function that needs to be called many places so I want to setup a
function so I can pass the form name and control name to the function to
do
some stuff. The calling form has

set_statusbartext Me.Form, Form.ActiveControl.Name

I'm trying to pass the form name and the control name to the following
function

Public Function set_statusbartext(frm As Form, ctl As Control)
Dim temp_ctr As Integer
frm.ctl.StatusBarText = ""
If frm.ctl.ListCount > 0 Then
If frm.ctl.ListCount < 15 Then
Do Until temp_ctr > frm.ctl.ListCount - 1
frm.ctl.StatusBarText = frm.ctl.StatusBarText & " [" &
frm.ctl.ItemData(temp_ctr) & "] "
temp_ctr = temp_ctr + 1
Loop
Else
frm.ctl.StatusBarText = "too many to display!"
End If
End If

End Function

the set_statusbartext function is passing the form name but the value of
the
control, not the control name...what am I missing? thanks!
 
The function is receiving a full reference to the control.
That means it can access any properties of the object.

I'm not clear what the code is supposed to be doing, but if you want to see
its name when the function is called, add this line:
Debug.Print ctl.Name
Then after calling it, open the Immediate Window (Ctrl+G) and you will see
the name there.

You can therefore use
ctl.name
in whatever place you want its name.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

PeterM said:
I don't understand... the calling form has
set_statusbartext Me.Form, Form.ActiveControl.Name
and the called function has
Public Function set_statusbartext(frm As Form, ctl As Control)
where do I put ctl.name
based on the above set_statusbartext call, it's passing the value of the
control, not it's name...what am I missing?

Allen Browne said:
Since you are passing ctl as a control, you can get its name as:
ctl.Name

(BTW, you don't need the frm variable in this code.)

PeterM said:
I have a function that needs to be called many places so I want to setup
a
function so I can pass the form name and control name to the function
to
do
some stuff. The calling form has

set_statusbartext Me.Form, Form.ActiveControl.Name

I'm trying to pass the form name and the control name to the following
function

Public Function set_statusbartext(frm As Form, ctl As Control)
Dim temp_ctr As Integer
frm.ctl.StatusBarText = ""
If frm.ctl.ListCount > 0 Then
If frm.ctl.ListCount < 15 Then
Do Until temp_ctr > frm.ctl.ListCount - 1
frm.ctl.StatusBarText = frm.ctl.StatusBarText & " [" &
frm.ctl.ItemData(temp_ctr) & "] "
temp_ctr = temp_ctr + 1
Loop
Else
frm.ctl.StatusBarText = "too many to display!"
End If
End If

End Function

the set_statusbartext function is passing the form name but the value
of
the
control, not the control name...what am I missing? thanks!
 
Since your function is expecting a reference to a control, not its name, you
need to call it by:

set_statusbartext Me.Form, Form.ActiveControl

In actual fact, your last statement ("the set_statusbartext function is
passing the form name but the value of the
control, not the control name") is incorrect: you're passing a reference to
the form, not its name.
 
Back
Top