One line of code for multiple labels

  • Thread starter babyatx13 via AccessMonster.com
  • Start date
B

babyatx13 via AccessMonster.com

I have a form that has about 100 labels on it each have the same dbl click
event procedure is there a way I can just write one line of code for all
labels instead of putting it in the click event for each one?

Thanks KB
 
T

tina

you can move the code into a public function, as

Public Function isMyCode()

<place here the code that's running in a dbl click event procedure>

Exit Function

the open the form in Design view, select all the labels together, and in the
Properties box (the Title bar of the box should say "Multiple selection")
add the function to the OnDoubleClick event line, as

=isMyCode()

the above *replaces* the [Event Procedure] text on the line.

hth
 
M

Mike Painter

Do you want to click a button and have that code exercised on all labels or
be able to select individual labels?
In teh former you would loop through teh collection and in the latter you
can create a function then paste a call to that into each label.

100 labels on a form usually sets off "Warning will Rogers" design question
alarms.
 
B

babyatx13 via AccessMonster.com

I am selecting individual labels. I don’t want to use a call function, I
want the code to be one line for all buttons. As it stands now the code is a
mile long.

The code is as follows for each label

Private Sub Label11_DblClick(Cancel As Integer)
DoCmd.OpenForm "frm_searchresults", acNormal, , "[Sec/Lot] = '" & Me!Label11.
Caption & "'"
End Sub

This example is from label # 11, obviously each label has a different number.

I thought about using a macro but I need to know how to tell which label I
have double clicked on before it will open the appropriate record associated
with that particular label.

Thanks
KB
 
G

Graham Mandeno

Hi KB

It looks like you are using label captions to display data. Are you sure
this is what you want to do?

If the controls were textboxes, not labels, you could have a general-purpose
function:

Private Function MyDblClick()
DoCmd.OpenForm "frm_searchresults", acNormal, , "[Sec/Lot] = '" _
& Me.ActiveControl & "'"
End Function

Then set the OnDblClick property of each textbox to:
=MyDblClick()

If you really need to use labels, then you will need to pass the name of the
label to your function:

Private Function MyDblClick(sLabelName as String)
DoCmd.OpenForm "frm_searchresults", acNormal, , "[Sec/Lot] = '" _
& Me(sLabelName).Caption & "'"
End Function

Then set the OnDblClick property of each label to:
=MyDblClick("NameOfLabel")

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


babyatx13 via AccessMonster.com said:
I am selecting individual labels. I don't want to use a call function, I
want the code to be one line for all buttons. As it stands now the code is
a
mile long.

The code is as follows for each label

Private Sub Label11_DblClick(Cancel As Integer)
DoCmd.OpenForm "frm_searchresults", acNormal, , "[Sec/Lot] = '" &
Me!Label11.
Caption & "'"
End Sub

This example is from label # 11, obviously each label has a different
number.

I thought about using a macro but I need to know how to tell which label I
have double clicked on before it will open the appropriate record
associated
with that particular label.

Thanks
KB

Mike said:
Do you want to click a button and have that code exercised on all labels
or
be able to select individual labels?
In teh former you would loop through teh collection and in the latter you
can create a function then paste a call to that into each label.

100 labels on a form usually sets off "Warning will Rogers" design
question
alarms.
 
M

Mike Painter

You will have to code each label separately.
If you get to two hundred labels you will have to code all of them
separately.
A table with [Sec/Lot] as a field allows any number of records.
A combobox on a form allows access to those with out searching and a linked
subform removes the need for opening a separate form.

I'd say no to doing such a thing unless I had it in writing and signed by
somebody who understood the problems with such an approach.

I am selecting individual labels. I don't want to use a call
function, I want the code to be one line for all buttons. As it
stands now the code is a mile long.

The code is as follows for each label

Private Sub Label11_DblClick(Cancel As Integer)
DoCmd.OpenForm "frm_searchresults", acNormal, , "[Sec/Lot] = '" &
Me!Label11. Caption & "'"
End Sub

This example is from label # 11, obviously each label has a different
number.

I thought about using a macro but I need to know how to tell which
label I have double clicked on before it will open the appropriate
record associated with that particular label.

Thanks
KB

Mike said:
Do you want to click a button and have that code exercised on all
labels or be able to select individual labels?
In teh former you would loop through teh collection and in the
latter you can create a function then paste a call to that into each
label.

100 labels on a form usually sets off "Warning will Rogers" design
question alarms.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top