How can I dynamically change the caption of a label on a form in run mode?

D

dsukovich

I have a form that is used for configuring the labels of up to 13
checkboxes. I click the checkbox I want to configure and then in a
separate field I enter what the checkbox label should read on a form,
what the label should read on a report and whether the checkbox is
supposed to visible or not. I will do this for each of the 13
checkboxes. There is a table behind the form holding these values I
will enter. The problem is, I am clicking on 1 of 13 checkboxes, I
need to be able to determine which label to change, that's the easy
part, and then change it. I have planned to use the Tag property of
the checkbox field to build label field name, but then, how do I set
the actual cpation of the label for that checkbox?
Thanks for your help,
Dsukovich
 
B

borgcollective1b

You need to know what the actual label name is for the selected
checkbox. If you have not already done so, you should name the labels
that you intend to change with names that are easily associated with
the corresponding checkboxes. If you use a common naming convention,
you can even get the labels to act like an "array" even though Access
does not truly support control arrays. Once you can actually identify a
checkbox's associated label, you can just set its caption property in
VBA.

- GH
 
D

dsukovich

Hi GH,
Thanks. I've already done that part. My checkboxes are have Tags of
Chk_1 ... Chk_13 and their labels are Lbl_1 ... Lbl_13.
See my code below to know where I'm stuck. Hopefully it is something
very simple for you.
For Each ctl In Controls
If TypeOf ctl Is CheckBox Then
If ctl.Value = -1 Then
Forms![F_Role_Config]!LabelTag = "Lbl_" &
Mid(Forms![F_Role_Config]!ChkTag, 5, 2)
' how do I set the label that has the TAG = LabelTag to the
caption I enter in the form ?
End If
End If
Next

In the area of my comment is where I need the code to set the label,
but, how is it done?

Thanks,
Dsukovich
 
G

Guest

Sorry, but I can't figure out exactly what you are trying to do. First,
there is no such thing as TypeOf and unless you have a variable or constant
named Checkbox, it has no meaning. There is also no such property as
LabelTag unless you have created it yourself. Where do you enter the label
value in the form?

Perhaps you could describe in more detail what you are trying to accomplish
so we can make some suggestions.
 
D

dsukovich

I have a form that is used for configuring the labels of up to 13
checkboxes. I click the checkbox I want to configure and then in a
separate field I enter what the checkbox label should read on a form,
what the label should read on a report and whether the checkbox is
supposed to visible or not. I will do this for each of the 13
checkboxes. There is a table behind the form holding these values I
will enter. The problem is, I am clicking on 1 of 13 checkboxes, I
need to be able to determine which label to change, that's the easy
part, and then change it. I have planned to use the Tag property of
the checkbox field to build label field name, but then, how do I set
the actual caption of the label for that checkbox?

On my Access form I have created a field: [LBL_CAPTION]
Also on my form is [LabelTag]
I put it there just for visibility. I'm contructing the tag of the
label I want to change the caption of. The caption is going to be in
[LBL_CAPTION]. I will type it there.

Therefore, if I click on Checkbox with the tag of CHK_1 and enter the
Caption "MY CAPTION1" into field [LBL_CAPTION], I know that field
[LabelTag] will have the value LBL_1, based on the above code.
How then, do I use this to actually change the Caption of the label on
my form that has the tag equal to LBL_1?

Thanks very much for your help,
DSukovich
 
G

Guest

I don't know that I can help any more than I already have. I can't seem to
understand what you are doing.
 
D

dsukovich

Nevermind -
I figured it out. Here is the correct code. You may use it if you
like.

Dim c, ctl As Control

For Each ctl In Controls
If TypeOf ctl Is CheckBox Then
If ctl.Value = -1 Then
ctl.Controls(0).Caption = Me.lblfield
End If
End If
Next
 

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