Share via

changing label's caption according to field's values in a report

Anonymous
2013-07-30T20:26:18+00:00

Hi

I have field1, field2 , .... ,etc. in a table, and I have a report based on that table.

Field1 takes only one of three values ( A, B ,or C e.g.)

The report contains a text box control ( txtField1) bounded to field1, and an unassociated label control.

How can I change the label's caption according to txtField1's value in print preview ?

For example; How can I let the report (when I open it in print preview) show the text "Number 1" in the label control for group A,"Number2" for group B, and "Number3" for group C

In other words, I am looking for a way  that effecting like conditional formatting, but to change label's caption rather than its formatting.

Thanks.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

  1. HansV 462.6K Reputation points
    2013-07-30T21:18:51+00:00

    I'd use a text box instead of a label. You can then set the Control Source of this text box to

    =Switch([field1]="A","Number1",[field1]="B","Number2",[field1]="C","Number3")

    Even better, create a small lookup table, with the distinct values of field1 in one field (the primary key), and the corresponding text strings in the other field.

    Create a query based on the original table and the lookup table, joined on field1 and the first field of the lookup table.

    If field1 can be empty, double-click the join line and select the option to return all records from the original table.

    Add all fields from the original table plus the second field from the lookup table to the query grid.

    Use the query as record source for the report.

    You can now use a text box without label bound to the new field.

    Was this answer helpful?

    2 people found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful