Passing a Label Control variable

  • Thread starter RexAbandon via AccessMonster.com
  • Start date
R

RexAbandon via AccessMonster.com

I have a form with several labels with a function associated to the On Click
event. I want to pass the label control to the function in the following
manner. (Simplified as follows)

=SampleFunction([Form],[Control])


Function SampleFunction(frm as Form, ctl as Control)
Msgbox frm.Name
Msgbox ctl.name
End Function

I tried using [ActiveControl] instead of [Control] but it will not work for a
Label as well.

Any help is appreciated.

Thanks,

Rex
 
D

Dirk Goldgar

RexAbandon via AccessMonster.com said:
I have a form with several labels with a function associated to the
On Click event. I want to pass the label control to the function in
the following manner. (Simplified as follows)

=SampleFunction([Form],[Control])


Function SampleFunction(frm as Form, ctl as Control)
Msgbox frm.Name
Msgbox ctl.name
End Function

I tried using [ActiveControl] instead of [Control] but it will not
work for a Label as well.

What exactly is the problem? You can certainly do what you're talking
about, but you must pass the control itself in your call to the
function. So if your label is named "lblFirstName", then your function
expression for the OnClick property would be:

=SampleFunction([Form],[lblFirstName])
 
R

RexAbandon via AccessMonster.com

Dirk said:
I have a form with several labels with a function associated to the
On Click event. I want to pass the label control to the function in
[quoted text clipped - 9 lines]
I tried using [ActiveControl] instead of [Control] but it will not
work for a Label as well.

What exactly is the problem? You can certainly do what you're talking
about, but you must pass the control itself in your call to the
function. So if your label is named "lblFirstName", then your function
expression for the OnClick property would be:

=SampleFunction([Form],[lblFirstName])


I guess I was trying to do it the lazy way and avoid putting the label name
in each expression. Like I said in the post I had several labels to change.
I was hoping there was something similar to the way a form is passed using
[Form].

Rex
 
D

Dirk Goldgar

RexAbandon via AccessMonster.com said:
Dirk said:
I have a form with several labels with a function associated to the
On Click event. I want to pass the label control to the function in
[quoted text clipped - 9 lines]
I tried using [ActiveControl] instead of [Control] but it will not
work for a Label as well.

What exactly is the problem? You can certainly do what you're
talking about, but you must pass the control itself in your call to
the function. So if your label is named "lblFirstName", then your
function expression for the OnClick property would be:

=SampleFunction([Form],[lblFirstName])


I guess I was trying to do it the lazy way and avoid putting the
label name in each expression. Like I said in the post I had several
labels to change. I was hoping there was something similar to the way
a form is passed using [Form].

No, I'm afraid you can't do that, because a label control can never be
the active control. I suppose you could write some complicated code
that calculates which label was clicked by where the cursor was -- its X
and Y coordinates -- when the Click event occurred, but I just don't
think it's worth it.
 
R

RexAbandon via AccessMonster.com

Dirk said:
[quoted text clipped - 13 lines]
labels to change. I was hoping there was something similar to the way
a form is passed using [Form].

No, I'm afraid you can't do that, because a label control can never be
the active control. I suppose you could write some complicated code
that calculates which label was clicked by where the cursor was -- its X
and Y coordinates -- when the Click event occurred, but I just don't
think it's worth it.

Thanks for your help Dirk!

Rex
 

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