is there an easy way

D

David

Hello

I have started getting into (semi-)OOP with VBA and I like how easy it makes
my life.
One thing that still seems to be a long-handed way of doing things is when I
have several (for example) labels on the same page that act in the same way
Currently I would do this:

Private Sub Label1_Click()
Me.Font.Bold = True
End Sub
Private Sub Label2_Click()
Me.Font.Bold = True
End Sub
Private Sub Label3_Click()
Me.Font.Bold = True
End Sub
.......
Private Sub Label23_Click()
Me.Font.Bold = True
End Sub

Every label is this small userform does the same thing is there a shorter
way of writing this or do I have to do it one at a time?

thanks
David
 
K

Klatuu

Here is a function that will do that for you. Put the function in a standard
module and you can call it from any form. You would call it like:
Call BoldLabels(Me)

Public Sub BoldLabels(frm As Form)
Dim ctl As Control
For Each ctl In frm
If ctl.ControlType = acLabel Then
ctl.FontBold = True
End If
Next ctl
End Sub
 
D

David

I will explain a bit better.

The user has a form up with about 40 labels.
They click on a few (about 5) which turn bold and print it off.

Only the clicked labels turn to bold.
I assume I would have to put this change in the click event of every label.

is that the case?
 
K

Klatuu

Then I misread you question. If you only want to do it one up for each
clicked label, then what you are doing is just as good as anything else.
 

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