07/20/08

 

Insert line breaks in Access labels through code

If you've ever needed to insert line breaks in a message box prompt, you most likely built a string that incorporated a line feed or carriage return character. Unfortunately, label objects aren't as forgiving when it comes to using these characters. If you're setting a label's Caption property with code, you'll find that the special control characters are interpreted as squares, since they're otherwise undisplayable. To successfully insert a line break in a label caption, you need to include both a line feed character and a carriage return character, entered consecutively. To do so, you can use the Chr() function, such as

Me.Label1.Caption = "Line 1" & _

Chr(13) & Chr(10) & "Line 2"

However, you can also simplify your code using an intrinsic constant, as shown below:

Me.Label1.Caption = "Line 1" & vbCrLf & "Line 2"

Created Date: 12/11/2001  Last Reviewed: 12/11/2001  Rev. Date: 

This site was last updated 06/11/06