Refering to the Control which "called" a procedure/sub


Question

Is there convenient code for returning the name of the control which was clicked on when a procedure was started - when the "control" is a rectangle that apparently cannot take the focus and will not therefore permit 'ActiveControl'? (Access95 btw)

The reason I ask (for clarification) It's a variation on the old "colouring your buttons" theme which I
have been reading about in the archives. I have successfully set up a coloured rectangle with the required onClick event. In the onMouseDown I have code which will change the SpecialEffect Property to "Sunken" and in the onMouseUp I have code to change the SpecialEffect Property to "Raised". However in writing this code I have had to explictly refer to this particular rectangle by name.

I could therefore just laboriously duplicate this code for each rectangle and adjust the name - but I would like to generalise. I could have a transparent button on top of the rectangle (which could use ActiveControl?) - but then I would have to synchronise names etc.

In Excel4 I seem to remember a macro instruction CALLER which would return information about the routine which called the current routine. Is there anything similar in Access which would effectively say "what you clicked on to run this procedure is called x"?

Alternatively any alternative ideas?

Answer


David,

Write a function:

Public Function ShpToggle(ByRef rfrm As Form, _
                                       ByVal vstrCtlName As String, _
                                       ByVal vblnDown As Boolean)
    If vblnDown Then
       rfrm(vstrCtlName).SpecialEffect = 2 'Sunken
    Else
       rfrm(vstrCtlName).SpecialEffect = 1 'Raised
       Doevents
       '*+
       '
       '  Call the function(s) to process your "button" click
       '
       '*-
    End If
End Function

and call it from OnMouseDown: =ShpToggle([Form];"shpCtlXName";True) OnMouseUp: =ShpToggle([Form];"shpCtlXName";False)

HTH,
Shamil

P.S. Modern soultion - use WithEvents feature.


Copyright 1999-2008 by Shamil Salakhetdinov.  All rights reserved.