Tuesday, November 22, 2011

How to add line breaks to ControlTip Text in Access

Whats the problem?

If you've ever tried to add line breaks or formatting to the ControlTip Text in a control in an Access project you will have noticed that you can add anything to the ControlTip Text property field and it will get put on a single line. I.e...


You can add any sort of tricky string to the property dialog box and get no useful result.


If you have spent any time thinking about property dialog programming you should already see whats going on... input validation.  The code behind the property dialog is "sanitizing" your input to prevent you injecting control characters, illegal characters and other types of idiot/malicious code.  This is a good thing... except when you want to do something like this intentionally.

Whats the solution?

The above description helped me identify the solution... avoid the input validation behind the property dialog rather than try to bend it to my will.  The hack is to add the formatted string for the ControlTip Text via code.  I use the Form_Load sub to set tricky control tip text for all the controls on the form that I want to have multi-line ControlTip Text.

I.e

Private Sub Form_Load()
     showTaskManager.ControlTipText = "Display the Batch Task Manager" & vbCrLf & "Some other text here"
   
End Sub

This will show up as a nicely formatted multi-line ControlTip.

Simple once you see it....

No comments:

Post a Comment