Home - Microsoft Access Development - Microsoft Access Tips
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.
funSetFontSize Me.lblName.Caption ' Get the font size for the Name
Me.lblName.FontSize = lngTitleFontSize ' Set the font size for the Name
Public Function funSetFontSize(strName As String) If lngTextLength >= 27 And lngTextLength < =28 Then
|
![]()