From: PSULionRP on
How can I continue a SQL Serever call in a Visual Basic Sub Procedure???

I have this syntax...

.Open "SELECT Table1.Column1 _
, RTrim(LTrim(Table2.Column1)) _
, RTrim(LTrim(Table1.Column2)) _
, RTrim(LTrim(Table1.Column3)) _
FROM Table1 Table1 _
INNER JOIN Table2 Table2 _
ON Table1.Column1 = Table2.Column1 _
WHERE Table1.Column1 IN ('Value1','Value2','Value3')"

I thought I could continue my SQL syntax with an "_" but I always seem to
get the error message on the FROM which states...

Compile error:

Expected: end of statement

Can someone help me out here???

Thanks in advance for your help.

PSULionRP

From: RDub on
You must Concatenate the quoted strings with ampersands and opening and
closing quotes

Open "SELECT Table1.Column1 " _
& ", RTrim(LTrim(Table2.Column1)) " _
& ", RTrim(LTrim(Table1.Column2)) " _
....
Rdub


"PSULionRP" <PSULionRP(a)discussions.microsoft.com> wrote in message
news:06F5966A-68B5-47E2-AF12-81B0BF936761(a)microsoft.com...
> How can I continue a SQL Serever call in a Visual Basic Sub Procedure???
>
> I have this syntax...
>
> .Open "SELECT Table1.Column1 _
> , RTrim(LTrim(Table2.Column1)) _
> , RTrim(LTrim(Table1.Column2)) _
> , RTrim(LTrim(Table1.Column3)) _
> FROM Table1 Table1 _
> INNER JOIN Table2 Table2 _
> ON Table1.Column1 = Table2.Column1 _
> WHERE Table1.Column1 IN ('Value1','Value2','Value3')"
>
> I thought I could continue my SQL syntax with an "_" but I always seem to
> get the error message on the FROM which states...
>
> Compile error:
>
> Expected: end of statement
>
> Can someone help me out here???
>
> Thanks in advance for your help.
>
> PSULionRP
>


From: MikeD on

"PSULionRP" <PSULionRP(a)discussions.microsoft.com> wrote in message
news:06F5966A-68B5-47E2-AF12-81B0BF936761(a)microsoft.com...
> How can I continue a SQL Serever call in a Visual Basic Sub Procedure???
>
> I have this syntax...
>
> .Open "SELECT Table1.Column1 _
> , RTrim(LTrim(Table2.Column1)) _
> , RTrim(LTrim(Table1.Column2)) _
> , RTrim(LTrim(Table1.Column3)) _
> FROM Table1 Table1 _
> INNER JOIN Table2 Table2 _
> ON Table1.Column1 = Table2.Column1 _
> WHERE Table1.Column1 IN ('Value1','Value2','Value3')"
>
> I thought I could continue my SQL syntax with an "_" but I always seem to
> get the error message on the FROM which states...
>
> Compile error:
>
> Expected: end of statement
>
> Can someone help me out here???
>


You can't split a string among multiple lines like that. You still have to
concatenate it like this:

.Open "SELECT Table1.Column1" _
& " , RTrim(LTrim(Table2.Column1)) " _
& " , RTrim(LTrim(Table1.Column2)) " _
& " , RTrim(LTrim(Table1.Column3)) " _
& " FROM Table1 Table1 " _
& " INNER JOIN Table2 Table2 " _
& " ON Table1.Column1 = Table2.Column1 " _
& " WHERE Table1.Column1 IN
('Value1','Value2','Value3')"


--
Mike
Microsoft MVP Visual Basic