Line Break

Depending on where you wish to insert a line break, the method you will need to use will differ. The one I use most consistently is the Microsoft Access constant known as ‘vbCrLf’. For example, if you have written code to create a message box such as:

MsgBox “The record has now been Saved. The database will now close".

will display in a message box as per below, with just the OK button as per below.

You may wish, though, to have the second sentence below the first sentence. To do this you could write the code for the message box as:

MsgBox “The record has now been Saved" & vbCrLf  & “The database will now close".

This will then display the message box in the message box as per below

The vbCrLf forces the second sentence to the second row in the message box to.

If you wish to have a space between the two rows, then just add another vbCRLF as per below:

MsgBox “The record has now been Saved" & vbCrLf  & vbCRLF & “The database will now close".


This helps to make your message box easier to read for the user.

You can also use this constant in other instances where you wish to set your text out in an orderly format. You may like to try the following:

  • In your VBA code to set out text in an orderly format to send an e-mail messages using the code click here, to see how to send an email using VBA code


Note: You cannot use the vbCRLF in queries, labels, or text boxes.

In labels and textboxes use, Ctrl & Enter on your keyboard the two examples are below

Textbox

="The record has now been Saved
the database will now close"

The Ctrl & Enter were pressed between 'Saved' and 'the' thus they are displayed on separate lines.  Note: keep all the words within the talking marks.

Label

The label is the same, but without the '=' sign and the talking marks.

The record has now been Saved
the database will now close


Once again the Ctrl & Enter were pressed between 'Saved' and 'the' thus they are displayed on separate lines.

Queries

Adding a line break to a query is a bit harder to do, the only way that maybe possible is to call a function to return formatted data.