Self-referencing Contols?

  • Thread starter Thread starter Martin Dashper
  • Start date Start date
M

Martin Dashper

How can an event method (eg On Click) determine the name of the
control to which it belongs? In other words, is there a 'self' type
of property or other suitable mechanism?

Martin Dashper
 
Martin,

I am not too sure that there is to be honest. Obviously the name of the
control appears before the event in the procedures declaration but there is
no way that I know of to get this control by using something like Me e.t.c.
You can however use Screen.ActiveControl to change properties e.t.c. to the
active control on a form (which I am assuming is why you are asking this
question). This would certainly suffice for the on click event as the active
control will be the control that the click event refers to (hope that made
sense).

HTH,

Neil.
 
I assume that you have one common event procedure for several buttons on
a form. You can do what you want if you plan for it during form design.
First, set the Tab order for the various buttons s.t one follows
another. For example here, let the first be named "btn01" (normally a
BAD name as it has no meaning). In your method, do this:

idxInUse = 1 + (Me.ActiveControl.TabIndex - btn01.TabIndex)

Now, if you specifically need the NAME of the button, create it as "btn"
followed by appropriate formatting of idxInUse. You might not need this
if you can use the index to go into arrays for whatever you want to do.

Note: The "1 + " refers to my usage starting at index 1. To start at
index 0, get rid of it.
-=-=
 
Martin said:
How can an event method (eg On Click) determine the name of the
control to which it belongs? In other words, is there a 'self' type
of property or other suitable mechanism?

Generally, a click event is connected to a single control
and you know the control.

OTOH, there are a few ways to call a general procedure where
you want to operate on whatever control triggered the event.
In this situation you can use Me.ActiveControl to refer to
the control object. You almost never need to determine the
name of the control once you have the control's object
variable, but if you do, just refer to its Name property.
 
Thanks Neil. Unfortunately the control I am clicking on is a
rectangle, which, it seems, cannot take focus and, so the command
'screen.ActiveControl' returns the name of the last control to have
focus and not the rectangle that I am clicking on.

Martin
 
Sounds like you will have to map the mouse coordinates to the form (not
nice). I assume that there is some way to get them -- i think i have
seen notes about this in the past. Good luck. Keep us posted.
-=-=
 
Martin said:
Thanks Neil. Unfortunately the control I am clicking on is a
rectangle, which, it seems, cannot take focus and, so the command
'screen.ActiveControl' returns the name of the last control to have
focus and not the rectangle that I am clicking on.

Rectangle? I think we'll need a lot more details about the
form's controls, how they're arranged and what you're trying
to do before anyone can make meaningful suggestions about
how to approach whatever situation you're attempting to deal
with.
 
Back
Top