By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,203 Members | 1,401 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,203 IT Pros & Developers. It's quick & easy.

Label Reference

P: n/a
Need some help with passing a label to a subroutine. I have a form with
lots of checkboxes. When the form loads i have a procedure that runs to
lookup values and check the appropriate boxes. If the box is checked I
want the label to look like a hyperlink. Then the user can click on the
label to open a new form that is linked to the checkbox. I had to make
labels that were not attached to the checkboxes. If you click a label
that is attached to a checkbox it toggles the value and I don't want
that. I have code that does this when the user first completes the form
and everything works fine. Now I want to populate the form when it
opens at a later time and that is where the trouble is.

When the FormLoad routine fires a dynamic routine runs to pull the
value for each box.
For Each ctl In Me.Controls
If ctl.ControlType = acCheckBox Then
. . .
This procedure then calls a subroutine that does the work. The problem
I'm having is passing the label to the subroutine. I have some naming
going on so I can use string functions to extract the label name from
the checkbox name. Since I'm doing this it doesn't recognize it as
label control. Does anyone know how I can do this dynamically so I
don't have to have 44 If statements or Case Select statements?

Thanks all
Mike

May 2 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I believe you're trying to do this:

If the CheckBox is named: "AccountOverDue"
and the associated label is named: "AccountOverDue_label"

then, you can do something like this to change the Label Caption:

Me(ctl.Name & "_label").Caption = "Click Me to get the Form"

The Me(ctl.Name & "_Label") gets translated to:

Me("AccountOverDue_label")

Which is the same as

Me!AccountOverDue_label

I don't believe you can change the format of a control to a Hyperlink
when in Form view. You probably have to be in Design view to do that.
I would suggest that you place a small CommandButton next to the
CheckBox and Enable/Disable it whenever the CheckBox is set to True
(checked).

Private Sub chkAccountOverDue_AfterUpdate()
' This routine will enable/disable the command button
' depending on the state of the checkbox (True = enabled).
Me!cmdAccountOverDue.Enabled = (Me!chkAccountOverDue = True)
End Sub

Then in the CommandButtons OnClick event procedure you'd open the
appropriate form.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRFfogIechKqOuFEgEQLNGwCeKg33jWMGwWKfzi/eVXLLRixPkQ0AniTA
2EjO2bJy1CGD3Q61I54Rm+kq
=fxIY
-----END PGP SIGNATURE-----

Mike wrote:
Need some help with passing a label to a subroutine. I have a form with
lots of checkboxes. When the form loads i have a procedure that runs to
lookup values and check the appropriate boxes. If the box is checked I
want the label to look like a hyperlink. Then the user can click on the
label to open a new form that is linked to the checkbox. I had to make
labels that were not attached to the checkboxes. If you click a label
that is attached to a checkbox it toggles the value and I don't want
that. I have code that does this when the user first completes the form
and everything works fine. Now I want to populate the form when it
opens at a later time and that is where the trouble is.

When the FormLoad routine fires a dynamic routine runs to pull the
value for each box.
For Each ctl In Me.Controls
If ctl.ControlType = acCheckBox Then
. . .
This procedure then calls a subroutine that does the work. The problem
I'm having is passing the label to the subroutine. I have some naming
going on so I can use string functions to extract the label name from
the checkbox name. Since I'm doing this it doesn't recognize it as
label control. Does anyone know how I can do this dynamically so I
don't have to have 44 If statements or Case Select statements?

May 2 '06 #2

P: n/a
I'm not actually making the label a hyperlink just giving it a look of
a hyperlink. I'm changing the forecolor and fontunderline properties.
The problem is doing this dynamically. I can't pass the label name to a
subroutine by extracting the label name from the checkbox name.
So for example I have a checkbox named "AD_Prior5" then the label name
is "Prior5".
When the form loads I'm looping through the controls looking for
checked boxes. If they are checked I want to dynamically pass the
related label to a subroutine to set the property values. Here's the
string functions I'm using to get the label name:
Mid(ctl.Name, 4, Len(ctl.Name) - 3)

I tried assigning the result from above to a string variable then
assigning that variable to a label variable by: lbl = Me(test)
I get an error Object variable or With block variable not set.

May 3 '06 #3

P: n/a
MGFoster, your idea worked. I had to change where in the code I
referenced the label with the Me statement.
Had to it in the subroutine and not in the formload area.
Thanks

May 3 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.