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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL code going onto a second line...? 1

Status
Not open for further replies.

zahara666

Technical User
Nov 1, 2001
78
0
0
CA
I have code where the SQl statement does not fit on one line. can someone tell me how to make VBA in access recognize that the second line belongs with the first line?

Thanks,
J.
 
The underscore _
dim sql as string

sql = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" & _
"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY" & _
"ZZZZZZZ"
 
csql = "SELECT ..."
csql = csql & " WHERE ...

Note the space before the WHERE. Be careful not to do

csql = "SELECT * FROM Table"
csql = csql & "WHERE Field1 = 1"

which equates to
"SELECT * FROM TableWHERE Field1 = 1" Peter Meachem
peter@accuflight.com

Support Joanna's Bikeathon
 
I prefer the underscore line extender option because you can lay out the SQL string neater.

As in

Dim strSQL As Sting
Code:
strSQL = "SELECT field1, field2, field3 " _
       & "FROM table1, table2 " _
       & "ON table1.field1 = table2.field2 " _
       & "WHERE (field3 " _
       & "BETWEEN " & ValueFirst & " " _
       & "AND " & ValueLast & ") " _
       & "ORDERBY field3

Which is a form of layout that SQL Server and other mainframe db coders will recognise.


'ope-that-'elps.

G LS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top