By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,253 Members | 1,689 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,253 IT Pros & Developers. It's quick & easy.

long strings in vba

P: n/a
Hi All,

I try to define a query in my code and the SQL is pretty long. I don't want
to write all the sql on a single line. Is there a way to continue the same
string on the next line?
If I remember correctly, I was reading some time ago about something like
this:

strQuery = "Select tblName.FieldName from _
tblName _
Where condition..."

I tried with the character underscore, but it doesn't work...

Regards,
Nicolae
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Thu, 8 Jul 2004 13:13:45 +1000, "Nicolae Fieraru"
<no****@please.cxm> wrote:
Hi All,

I try to define a query in my code and the SQL is pretty long. I don't want
to write all the sql on a single line. Is there a way to continue the same
string on the next line?
If I remember correctly, I was reading some time ago about something like
this:

strQuery = "Select tblName.FieldName from _
tblName _
Where condition..."

I tried with the character underscore, but it doesn't work...

Regards,
Nicolae

You need to finish each line with double quotes and begin the next
line with an ampersand and double quote to concatenate the string.
Like...

strQuery = "Select tblName.FieldName from " _
& "tblName " _
& "Where condition..."

Note there must be a space after the quote and before the line
continuation character (underscore). Also, take note of spaces where
needed in the SQL string - they are easy to miss.

- Jim

Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.