PC Review


Reply
Thread Tools Rate Thread

Access 2003, Determining which control has been clicked

 
 
Jerry Pine Pollen
Guest
Posts: n/a
 
      19th Aug 2008
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.

Any advice?
 
Reply With Quote
 
 
 
 
Stuart McCall
Guest
Posts: n/a
 
      19th Aug 2008
"Jerry Pine Pollen" <Jerry Pine (E-Mail Removed)> wrote in
message news:2659C07C-15CB-4DDD-BD41-(E-Mail Removed)...
> 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.
>
> Any advice?


Try this on for size. Create a public function in a standard module which
takes a form object as a parameter, eg:

Public Function FunctionName(frm As Access.Form)

Inside the function, use frm.ActiveControl to determine which rectangle was
clicked. Also do the color thing in here.

On your form in design view, select all the rectangles, open the property
sheet and go to the Events tab. Put this into the OnClick property:

=FunctionName([Form])

That sets the property for all selected controls.


 
Reply With Quote
 
Rick Brandt
Guest
Posts: n/a
 
      19th Aug 2008
Stuart McCall wrote:
> Try this on for size. Create a public function in a standard module
> which takes a form object as a parameter, eg:
>
> Public Function FunctionName(frm As Access.Form)
>
> Inside the function, use frm.ActiveControl to determine which
> rectangle was clicked. Also do the color thing in here.
>
> On your form in design view, select all the rectangles, open the
> property sheet and go to the Events tab. Put this into the OnClick
> property:
> =FunctionName([Form])
>
> That sets the property for all selected controls.


Problem though is that since a rectangle cannot have focus it will never be
the active control. One could use TextBoxes instead though and then it
would work.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com


 
Reply With Quote
 
Marshall Barton
Guest
Posts: n/a
 
      19th Aug 2008
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]
 
Reply With Quote
 
Stuart McCall
Guest
Posts: n/a
 
      19th Aug 2008
"Rick Brandt" <(E-Mail Removed)> wrote in message
news:tHqqk.21966$(E-Mail Removed)...
> Stuart McCall wrote:
>> Try this on for size. Create a public function in a standard module
>> which takes a form object as a parameter, eg:
>>
>> Public Function FunctionName(frm As Access.Form)
>>
>> Inside the function, use frm.ActiveControl to determine which
>> rectangle was clicked. Also do the color thing in here.
>>
>> On your form in design view, select all the rectangles, open the
>> property sheet and go to the Events tab. Put this into the OnClick
>> property:
>> =FunctionName([Form])
>>
>> That sets the property for all selected controls.

>
> Problem though is that since a rectangle cannot have focus it will never
> be the active control. One could use TextBoxes instead though and then it
> would work.
>
> --
> Rick Brandt, Microsoft Access MVP
> Email (as appropriate) to...
> RBrandt at Hunter dot com


Of course. Yes they would have to be textboxes. I'd forgotten the focus
problem.

Thanks for jumping in.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Determining the DataViewRow that was clicked in a DataGridView Mircea Ion Microsoft ADO .NET 1 11th Apr 2009 07:06 AM
Determining which Print Button was clicked Reggie Microsoft Excel Programming 2 18th Aug 2008 02:12 AM
Determining which Menu Item is Clicked Elliot Microsoft VB .NET 1 10th Mar 2005 10:19 PM
Problem determining when user has clicked outside my UserControl Rhy Mednick Microsoft C# .NET 1 1st Jun 2004 08:22 AM
Re: Determining if a hyperlink button to external site has been clicked. William F. Robertson, Jr. Microsoft ASP .NET 0 30th Jun 2003 08:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:37 PM.