Using a sting as a command

  • Thread starter Thread starter Steven
  • Start date Start date
S

Steven

I have a sting variable named varSting. The value to the
variable is "Me.Co001.Caption = CIS". Me.Co001 is a label
in a form that I want to read as CIS. I have many labels
on the form and I want to be able to control the captions
depending on the values in a table. I am tring run a
command like DoCmd.RunCommand varString but is not
correct.

Can anyone help me on how to run this operation so I can
use a string variable but actually run the line of cammand
that the variable says. Also have I set the variable up
correctly.

Thank you,

Steven
 
RunCommand only run one of the preset commands using one of the "acCmd..."
constants.

What's wrong with:

Me.Co001.Caption = "CIS"

?

Note: You need to enclose the Caption value in String delimiters.
 
The problem is that I have 30 labels and the labels will
have different captions depending on which company the
user has selected and therefore I need flexibility in
doing the Me.Co001.Caption = "???".

I am opening a recordset of the table and using
rs("FieldName") to get the information but there are
conditions which determine which label will be changed.
Therefore I am trying to use a total string variable with
the entire command of "Me.Co001.Caption = 'CIS'". In
reality the "001" of the Me.Co001.Caption is actually a
value of a field in a table and I am stringing the whole
thing together...but I dont know how to make the string
run like a regular line of code.

Thank you for your response.
 
Do you mean you get the LabelControlName and the Caption from a Recordset
rs?

If that the case, use:

Me.Controls(rs.Fields("LabelControlNameField")).Caption = _
rs.Fields("LabelCaptionField")
 
Back
Top