Refer to control in procedure

W

Will

I have a form with rectangles on it which display the shape of offices. My
Code is the following:

Private Sub shpAB12567C_Click()
Call SelectLoc "shpAB12567C"
Me.shpAB12567C.BackColor = vbRed
End Sub

Is there a way to pickup the sub name/control name from within the
procedure, to save me from specifying it for each control on the form. E.g.
I'm looking to do the following so I can just copy & paste for each control.

Private Sub shpAB12567C_Click()
Call SelectLoc Me.ControlName
Me.ControlName.BackColor = vbRed
End Sub

I have looked at active control but it doesn't work with rectangle shapes.

thanks
 
M

Michel Walsh

Hi,


nope, because the procedure belongs to the form, not to the control, and can
be, technically, called from any where, form code, within the form-module...
(such as TWO controls calling the same _Click procedure IS doable), so no
UNIQUE control is assigned to a _Click procedure...

But you can try to play with Screen.ActiveControl or Screen.PreviousControl.
Note that code using such control is very hard to debug "step by step" since
the Screen Active control is modified live by activation of the debugger
screen, though the debugging process.


Hoping it may help,
Vanderghast, Access MVP
 
M

Michel Walsh

:)



Vanderghast, Access MVP


Klatuu said:
This is a good point you bring up. I often forget to warn people code
using
ActiveControl, PreviousControl, or ActiveForm don't do will in debug. But
then I write code that doesn't need to be debugged :)
 

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