Results 1 to 6 of 6
  1. #1
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862

    SQL String need to use underscore for continuation of line of code

    My SQL works fine with the underscores I have in place now. Sometimes my SELECT statement gets real long and I can't seem to figure out how to continue the SELECT statement on an additional line of code. I am not great with SQL and it takes me time to figure out quotes vs. apostrophe enclosed quotes, etc. while using different data types. So I can not tell if I am doing something wrong or VBA just does not allow for this.

    And how do I paste text within the body of my post so it appears in its own window in the body?


    strWhere = ""

    strWhere = "SELECT [qryMasterSum].[MoveDate], [qryMasterSum].[PickCity], [qryMasterSum].[DelCity], [qryMasterSum].[TruckDurringMove], [qryMasterSum].[EquipLicNum],[qryMasterSum].[Import]" _


    & "FROM [qryMasterSum]" _
    & "WHERE (qryMasterSum.DriverID)=" & glngDriverId & " AND ((qryMasterSum.MoveDate)>=#" & gdtDate & "#)AND (((qryMasterSum.MoveDate) <=#" & gdtDateEnd & "#))" _
    & "ORDER BY [MoveDate];"

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Need spaces in the string so parts don't run together when compiled. Here's how I do it:

    strWhere = "SELECT MoveDate, PickCity, DelCity, TruckDurringMove, EquipLicNum, Import " & _
    "FROM qryMasterSum " & _
    "WHERE DriverID=" & glngDriverId & " AND MoveDate Between #" & gdtDate & "# And #" & gdtDateEnd & "# " & _
    "ORDER BY MoveDate;"

    You can go to the Advanced post editor and use tools to enclose text within CODE or QUOTE tags or you can type them. Use the tools first to learn the tag structure.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by June7 View Post
    Need spaces in the string so parts don't run together when compiled.
    Thank you June. I think what you are referring to happened in my attempt to paste my code into the post. I pulled that example out of an existing DB that functions well. I see what you did by naming the fields by eliminating brackets and the query name. That definitely shortened the SELECT part of the statement. I will try that for sure.

    Is there a way to use the underscore smack in the middle of the SELECT statement. For example using more quotes and an ampersand together with an underscore.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Sure, break it anywhere you want.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    I used to try and try to break my SQL in the middle of a SELECT or WHERE statement. I could never get right and just gave up on it. I have been writing code 1000 pixels wide for ever.

    So I just focused on counting characters and spaces like you mentioned and presto, it worked. Plus, I didn't realize I could do without the brackets.

    Thanks June.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    The brackets would be needed if names have spaces or special characters/punctuation (underscore is exception) or are reserved words. The query name qualifier would be needed if pulling fields with same name from several sources in a JOIN sql.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. How Can I: Create a Continuation Recrod?
    By RichardAnderson in forum Forms
    Replies: 8
    Last Post: 08-21-2013, 10:42 AM
  2. Replies: 7
    Last Post: 05-28-2013, 09:11 AM
  3. Continuation - Past Due (30, 60, or 90)
    By dgaletar in forum Access
    Replies: 33
    Last Post: 02-17-2013, 03:26 PM
  4. How to execute Line of Code
    By jo15765 in forum Programming
    Replies: 4
    Last Post: 06-22-2011, 05:37 PM
  5. How to do line by line compare of VB code?
    By Buakaw in forum Access
    Replies: 2
    Last Post: 02-14-2011, 11:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums