Access 2016 VBA break line

Dick7Access

Dick S
Local time
Yesterday, 19:39
Joined
Jun 9, 2009
Messages
4,295
Access 2016 VBA I can’t break my lines of code. I have googled for hours and I have tried every combination of [ _ & ] I can think of. What’s the secret?
 
The line continuation character is space + underscore, so " _"

If you are constructing a string, then you need to terminate the string, ampersand it to the next line, add your line continuation, and then restart your string, like...
Code:
dim tmp as string
tmp = "This is a string that is so long, we will continue its " & _
   "construction on the next line."
...but otherwise you can just continue the line, like...
Code:
Private Function LongListOfParams( _
   Param1 as string, _
   Param2 as string, _
   Param3 as string)
Mark
 
The line continuation character is space + underscore, so " _"

If you are constructing a string, then you need to terminate the string, ampersand it to the next line, add your line continuation, and then restart your string, like...
Code:
dim tmp as string
tmp = "This is a string that is so long, we will continue its " & _
   "construction on the next line."
...but otherwise you can just continue the line, like...
Code:
Private Function LongListOfParams( _
   Param1 as string, _
   Param2 as string, _
   Param3 as string)
Mark

Thanks, that did it. I was missing [" " ].What the google spots I found did not include the [" " ] at the second line.
 
The placement of the ampersand is not critical. I normally put the & at the start of the next line to show me that the line is a continuation as well

Code:
tmp = "This is a string that is so long, we will continue its "  _
 & "construction on the next line."
 
Interesting visual aid, Cronk. I like it.
 
Doc,

Exactly my reaction when I saw it in a db I was working on, developed by someone else.
 
Funny, because I like it at the end of the line. Find it looks dorky hanging off the front. Preference.
 
The placement of the ampersand is not critical. I normally put the & at the start of the next line to show me that the line is a continuation as well

Code:
tmp = "This is a string that is so long, we will continue its "  _
 & "construction on the next line."

Additionally I align the ampersand with the eqals and always put any spaces at the beginning of the line where they are easily confirmed

Code:
strSQL = "SELECT blah" _
       & " FROM sometable"
The alignment avoids the "dorky" look mentioned by Mark.
 
It's a good job this forum isn't populated by nerds or the grammar police...


oh wait a minute
 

Users who are viewing this thread

Back
Top Bottom