PDA

View Full Version : [SOLVED:] Application level click event for shape



garyj
10-23-2023, 05:39 PM
Hello...

I am working on a code which will use the data in tables to draw various lengths of rectangles on a time-map. In other words, if the bus is being used for 2 days, the rectangle will be 2 days long on the calendar. Since the company may purchase new coaches from time to time, I don't want to pre-determine all the rectangles, but let the code create them. In general that is easy enough. But where I find the difficulty is in clicking on that line to bring up the details contained in the filtered table (driver, bus no, date-time out, date-time in). I will describe the reason for the difficulty below.

I chose to use an Active-X label for the shape, because it cannot be selected once design mode is off. If I give that shape a name, then I can easily create a click event as follows:


Private Sub Shape1_Click()
'stuff about shape
End Sub


That works. But it means I have to assign specific shapes for how many possible buses due to purchase, sale, loss, etc. So what I want is to use the code to create shapes as needed, regardless of their names, and to use the data on the sheet to assign length, etc. It could then make a label (bus number) which is used to find other data during the click. The click I need is for shapes in general. You click or double click and the one event is triggered no matter what shape or item on the worksheet is clicked. Then the code could eliminate certain items by

"If shapes.name = "notthisshape" then exit sub.

I have found some answers suggesting that I use Application.Caller, but they didn't show how I would assign the trigger.

That is the idea, but is this at all possible?
If not, any suggestions of which direction I could go?

Thanks in advance.
Gary

Paul_Hossler
10-23-2023, 06:03 PM
Simple example

garyj
10-23-2023, 10:31 PM
Simple example

Thanks for that, Paul.

You assign the same Macro to each box created, give each a different name on creation, and use that name to figure out which one is being clicked on.
I like the possibilities.

:yes:yes

Gary