Re: SQL code too long, what is syntax to split to second line?

  • Thread starter Thread starter Douglas J. Steele
  • Start date Start date
D

Douglas J. Steele

Space Underscore.

However, if you're trying to continue a string, you need to end the string
and concatenate it to the beginning of the continued string:

docmd.runSQL "Insert into tblTableName (Field1" & _
"Field2) SELECT A, B FROM " & _
"MyTable WHERE Select = True"

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



McLean J said:
I have a line of code for...
docmd.runSQL "Insert into tblTableName (...............

This append query is too long for one line... will actually take 3 lines
of code but I can't remember what the syntax is at the end of line 1 and the
beginning of line 2.
 
docmd.runSQL "Insert into tblTableName (Field1" & _
"Field2) SELECT A, B FROM " & _
"MyTable WHERE Select = True"

You also need to make sure you don't forget the space _inside_ the string
where you are breaking it

.... "INSERT INTO tblTableName (Field1, " & _
"Field2)

(check out the end of the first line...)


All the best


Tim F
 
Tim Ferguson said:
You also need to make sure you don't forget the space _inside_ the string
where you are breaking it

.... "INSERT INTO tblTableName (Field1, " & _
"Field2)

(check out the end of the first line...)

Good catch, Tim. However, if I'd remembered the comma, the space wouldn't
actually have been required...
 
Tim said:
You also need to make sure you don't forget the space _inside_ the string
where you are breaking it

.... "INSERT INTO tblTableName (Field1, " & _
"Field2)

(check out the end of the first line...)

I find this difficult to read; and since the concatenation has to be
done runtime anyway, I use this approach:

cSQL = "SELECT <select> FROM <table>"
cSQL = cSQL & " WHERE <whereclause>"

or optionally, if the statement must be readable later,

cSQL = cSQL & vbNewline & "WHERE <whereclause>"
 
Back
Top