Help with handling events

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

Guest

Hoping that someone out there can help me with this...

I have a form with about 250 labels on it. Each label is named in such a
way that I can make them visible/invisible as needed.

Here's what I'd like to do. When a visible label is clicked, it will open
up another form. However, I'd rather not write On_Click event procedures for
250 labels!

I was hoping to use the "Handles" extension on a subroutine, similar to VB,
but it doesn't seem to exist in VBA....or does it?

I also tried adding an On_Click event to the form's detail that would
capture the mouse's XY coordinates, and calculate what label the pointer was
floating over. However, since the labels are in front of the form detail,
and they have empty On_Click events, the sub won't run.

I'm thinking some sort of transparent image map that would reside in front
of the labels would work great. Is there such a thing?

Any help would make my day.

Thanks!
 
Here is an easy way you can do it and minimize the code and effort.

First, create a function in your form module that will open the form based
on the label that is Clicked. It will need one argument so you will know
which label was clicked.

Private Function SelectOne(intSelect as Integer)
dim strFormName as String

Select Case
Case 1
strFormName = "frmRpt1"
Case 2
strFormName = "frmRpt2"
Case 3
strFormName = "frmRpt3"
.........
Case 250
strFormName = "frmRpt250"
End Select
Docmd.OpenReport strFormName

Then for each label put a call to the function with the related number as
its argument in the Click Event text box on the Events tab of the Properties
Dialog:

=SelectOne(1)

250 labels on one form is a lot
 
Perfect! That will beat 250 event procedures.

Yeah, 250 labels is a lot. I couldn't think of any other way to do what I
wanted to do.

I'm creating a dynamic line-style "RF Spectrum" based on table data, and the
spectrum has 125 possible channels. Add another spectrum for specific
insertions, and I have 250. I don't want the channels to appear on the line
if they don't exist, so labels came to mind when I made the form.

Now to add the function to 250 labels. <cry> Still, it's better than a
really long class module. :) Thanks much for your help!

J
 
How about a couple of combo boxes, one for each type of spectrum?
I think it would be easier for the user to use than having to read a screen
of 250 very small labels?
 
I see your point, the only problem is that I wanted to provide a quick
overview of the selected spectrum as it would conceivably appear on a
spectrum analyzer. The combo box didn't fulfill that requirement. Luckily,
the label placement is surprisingly easy on the eyes.

I did remove the second spectrum line. Now I only have 125 labels to run
through, which helped system performance.

J
 
Well, at least you are doing it for a good reason. I had to ask. Sometimes
we jump on the first solution and later find there was a better one.
Glad I could help.
 
Back
Top