Finding out which control was clicked on a form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Using Access 2000 SP3
I've got a calendar form with 365 labels on it. I would like to be able to
click on one of them and have some code determine which label had been
clicked (i.e. I don't want to have to write 365 OnClick subroutines). Is this
possible?
 
Using Access 2000 SP3
I've got a calendar form with 365 labels on it. I would like to be able to
click on one of them and have some code determine which label had been
clicked (i.e. I don't want to have to write 365 OnClick subroutines). Is this
possible?


Since labels can not receive the focus, you can not use
Me.ActiveControl to refer to the one that was clicked.

Place a transparent command button on top of the entire set
of labels. Then use the MouseUp event procedure to
translate the mouse's X,Y corrdinates to a label's name.

Thiis is made far easier if the labels are all the same
size, laid out in a nice grid pattern, have no space between
them, and are named according to their position in the grid.
E.g. lbl00_00 at the upper left, lbl00_01 to the right, etc.
Then the mouse coordinates can easily be translated using a
simple expression:

intRow = Fix(Y / lbl00_00.Height)
intCol = Fix(X / lbl00_00.Width)
strLabelName = "lbl" & Format(intRow,"00") _
& "_" & Format(intCol,"00")
strCap = Me(strLabelName).Caption
 
Nice one! Thank you

Marshall Barton said:
Since labels can not receive the focus, you can not use
Me.ActiveControl to refer to the one that was clicked.

Place a transparent command button on top of the entire set
of labels. Then use the MouseUp event procedure to
translate the mouse's X,Y corrdinates to a label's name.

Thiis is made far easier if the labels are all the same
size, laid out in a nice grid pattern, have no space between
them, and are named according to their position in the grid.
E.g. lbl00_00 at the upper left, lbl00_01 to the right, etc.
Then the mouse coordinates can easily be translated using a
simple expression:

intRow = Fix(Y / lbl00_00.Height)
intCol = Fix(X / lbl00_00.Width)
strLabelName = "lbl" & Format(intRow,"00") _
& "_" & Format(intCol,"00")
strCap = Me(strLabelName).Caption
 
Back
Top