Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Line Feed in VBA

Status
Not open for further replies.

PL01

Technical User
Jun 9, 2008
57
US
What is the command to have VBA break up a block of text? i.e.
Var = "This Block of text is " & [new line here] & "too long for a single line".

What VBA code will break the text up into two lines when it comes up on the form or in a report?
 
vbcrlf

Which is a VB constant for Carriage Return and Line Feed. It is shorthand named constant for the combination of Chr(13) & Chr(10).
 
My recommendation: define constants in a general module like

Public Const NL As String = vbNewLine 'New line
Public Const DL As String = NL & NL 'New line after space
Public Const DQ As String = """" 'Double quotes
Public Const S12 As String = " " '12 Spaces

and then use your own short-cut constants

like

Msgbox "This Works." & NL & "Good!"

Best, georgesOne
 
thanks. I had tried Chr10 and Chr13 but not together.
 
How are ya PL01 . . .

You can also use the constant [blue]vbNewLine[/blue]. I always have the following two constants in the declaration header of a module for [blue]global access[/blue]:
Code:
[blue]Public Const NL As String = vbNewline [green]'new line[/green]
Public Const DL As String = NL & NL  [green] 'skip a line[/green][/blue]

As an example I'll breakup the following "[blue]Now is the time For all good men To come to The aid of their countrymen[/blue]"
Code:
[blue]   Dim str As String
   
   str = "Now is the time" & NL & _
         "For all good men" & NL & _
         "To come to" & NL & _
         "The aid of their countrymen"
   Debug.Print str[/blue]
[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
OLD definitions in the mechanical typewriter/printer days:

Carriage Return: The command used to either return the carriage or printhead, to the beginning-of-line position, as in an old typewriter. Used alone, the previously typed characters in the line, could be overtyped.

Line Feed: The command used to turn the platen forward one position. Used alone, produces a result like...
[tt]
Line Feed here--+
|
V
Now is the time for all good men[highlight] [/highlight]
to come to the aid of their country.
[/tt]


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
One can use one of the following

vbCrLf - Carriage Return and Line Feed
vbCr
vbLf
vbNewLine - Carriage Return and Line Feed

Herman
Say no to macros
 
...thank you very much for the information. But where are all the VBA commands conveniently indexed? I searched high and low for them in Access help. Is there a definitive text? I use the two Access for Idoits books which are very good to learn from - but the indexing is completely deficient. It's difficult to finds things in the thousand pages.
 
When in the VBE the F2 and F1 keys are your friends.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top