Label Caption on Subform from Textbox Value on Main Form

S

Steve P

On sfmProducts I have Label1 that is associated with txtColumn1. On
frmProducts I have txtColumnCaption1. I would like to have sfmProducts
display in datasheet view and have the caption of Label1 on the subform set
to the value of txtColumnCaption1 on the main form.

If I enter the following formula as the Caption of Label1 then the column
heading in datasheet view displays the formula itself.

=[Forms].[frmProducts]![txtColumnCaption1].[Value]

If I enter the same formula for the Control Source of txtColumn1 then the
value from the main form does indeed display.

What am I doing wrong?
 
J

Jeanette Cunningham

To use the expression =[Forms].[frmProducts]![txtColumnCaption1], change the
label to a textbox. Set its enabled property to No and its locked property
to Yes.

To use a label instead, write some code like:
Me.Label1.Caption =[Forms].[frmProducts]![txtColumnCaption1]
Where to put that code?
Every time txtColumnCaption1 changes, the value of Label1 on the subform
needs to change.
What makes the value of txtColumnCaption1 change?


You will find that you don't need to put .[Value] in the expression.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
R

Rob Parker

Hi Steve,

The thing you're doing wrong is using a label control. As you've found, it
cannot evaluate an expression in its caption, where a textbox can evaluate
an expression set as its ControlSource. Simply change the label to a
textbox; you can set its propertyies to Enabled = No and Locked = Yes to
prevent access to it, and when the form displays users will not know the
difference. About the only thing you lose is the ability to link it to a
textbox, so that they move together; but once you've designed your form,
that's really irrelevant.

HTH,

Rob
 

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