Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Q - dynamically addressing labels in a subform

Status
Not open for further replies.

RansomEli

Programmer
Jul 27, 2005
4
US
Thought I had asked the right question and worked this out, but not quite....

I have a form and wanted to use VBA to dynamically label a group of labels ( LabelSev1, LabelSev2...LabelSev8).

Thanks to this forum, I used the following code:

For x = 1 to 8
Me.Controls("LabelSev" & x).Caption = "Severity Level" & x
Next x

Here is my problem: I moved the form into a main form as a subform.

The subform is named SavedRiskMatrixValues. The following
code works: SavedRiskMatrixValues!LabelSev1.Caption = "good"

However, I get errors when I try to generate a command like:

SavedRiskMatrixValues!("LabelSev" & x).Caption
or
Forms!SavedRiskMatrixValues!Controls("LabelSev" & x).Caption

Is there a way I can save myself from typing out each label?

Thanks in advance from a newbie.
 
Perhaps this ?
SavedRiskMatrixValues.Form.Controls("LabelSev" & x).Caption

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
RansomEli,
Not that PH needs any more stars but if he has provided the answer to your question, you really should click the link to "Thank PHV...". This both recognizes PH for his time and marks the thread as answered ;-)

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top