Setting Font Size Dynamically in a Label
The following are some samples of VBA code that may prove useful.
Sometimes you want to set the font size of a label in a form or report depending on the length of the text to be displayed. For example, you may have a report that prints a person’s name in a fixed length label in the header. As names can vary in length, you want to use bigger font for shorter names and smaller for larger names.
The example below lists a sample set of font sizes for names ranging from under 27 characters to over 42 characters. The comments at the top list the font size for forms and the font size for reports. You will need to experiment for your own particular situation. First create the table at the top, then use those figures in the if statements.
To use the function store it in a module.
Assume you have a label called lblName in a form or report. Use the following in the form or report OnOpen event.
Me.lblName.FontSize = lngTitleFontSize