Jerry Pine Pollen <Jerry Pine
(E-Mail Removed)> wrote:
>I've been searching discussion groups (here and elsewhere) for days but can't
>find anyone who has addressed my question.
>
>In Access 2003, I've got a form with a mosaic of rectangles representing
>various locations in our organization. I change the background color of the
>rectangle or text within a rectangle depending on the specific data for that
>location. When a user clicks on one of the location boxes, I want to bring
>up a data form specific to that location. However, the only method I can
>figure out so far is to have an onclick event for every single rectangle.
>I've got that working for a representative rectangle and it works great
>except that I've got 300 rectangles and counting. That makes for a program
>construction and maintenance nightmare.
>
>Conceptually, what I would like to do is to have the form determine which
>rectangle was clicked and then pass the parameters to a common data
>management routine to decide what form and data to load. I can poll through
>all the rectangles but don't see a way to tell if one has been
>selected/clicked, since rectangles don't have an "onGotFocus" property.
If the rectangles are laid out in a regular pattern, then
you can place a large, transparent command button on top of
all of them. Then you can use the button's MouseUp event's
X,Y coordinates to calculate which rectangle was under the
mouse. For example, if your rectangles make up a uniform 3
by 3 grid and the rectangles are named box11, box12, box13,
box21, etc, then the clicked rectangle is:
Me("box" & (X \ box11.Width +1) & (Y \ box11.Height))
This concept gets real messy real fast if the rectangles are
not laid out in a uniform grid. In a worst case scenario,
you would have to cover the whole form section with the
button and loop through all the rectangle controls (named
box1, box2, ..., box300) comparing X and Y to the control's
Left, Width, Top and Height properties:
For k = 1 To 300
With Me("box" & k)
If X >= .Left And X <= .Left+.Width And _
Y >= .Top And Y <= .Top+.Height _
Then
'do your thing
. . .
Exit For
End If
End With
Next k
--
Marsh
MVP [MS Access]