Results 1 to 8 of 8
  1. #1
    jasonbarnes is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2010
    Location
    NC
    Posts
    56

    Setting SQL = string

    What is the proper syntax for setting this string equal to this sql statement?

    Dim SumofBusTEUS As String

    SumofBusTEUS = "SELECT Sum(tblTestData.SumOfTEUS) AS SumOfSumOfTEUS"


    FROM tblTestData WHERE tblTestData.#BUSRULE Is Not Null);"


    I can run this query seperate and it returns 1 lone value. However when i write it in VBA it gives me a compile error stating expected : end of statement at the WHERE clause.

    Help?!?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You close off the string after the field alias and never restart it. You might find it simpler to have it all on one line and get it working, then work on using line continuation characters (which you don't have in there) to get it onto multiple lines. You also have an extra parentheses at the end. You'll probably also need to bracket the field in the WHERE clause due to the inadvisable symbol.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jasonbarnes is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2010
    Location
    NC
    Posts
    56
    Dim SumofBusTEUS As String

    SumofBusTEUS = "SELECT Sum(tblTestData.SumOfTEUS) AS SumOfSumOfTEUS _
    FROM tblTestData WHERE (((([tblTestData].[#BUSRULE])) Is Not Null));"

    I added the _ to make the syntax continue.. now it kicks out at FROM which is the beginning of the second line.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    This type of thing:

    Code:
      strSql = "SELECT OrderMasterID, CustomerID, LastName, OrderSubtotal, OrderDate, " _
             & "SchedTravelDate, ConfirmationCode, ActualTravelDate, Reconciled, AcctBalID " _
             & "FROM tblAccountBalance " _
             & "WHERE 1=1 "
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    jasonbarnes is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2010
    Location
    NC
    Posts
    56
    Thanks so much.

    I thought I had seen a continuation character before, just couldn't remember what it was. I was in a hurry and didn't find it with a quick search before I left work. I think this will get me really far in what I'm trying to do.

  6. #6
    jasonbarnes is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2010
    Location
    NC
    Posts
    56
    Now that I have this resolved, I put it all in a public sub on the form I wanted to use it on.

    Now, I'm trying to set a textbox control source equal to the string. First off am I correct in how I'm going with this. Second whats the correct way to do that. I can't find much information on this at the moment.

    I was thinking it would just be =(SumofBusTEUS)

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    There would have to be more to the code, but it would be:

    =SumofBusTEUS
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    jasonbarnes is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2010
    Location
    NC
    Posts
    56
    I started a new thread and resolved this using...

    =DSum("sumOfTEUS","tblTestData","tblTestdata.[ORG_DES_CI] is not null")


    This simplied what I was trying to do. Thanks for the help.

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

Similar Threads

  1. order by setting itself
    By byterbit in forum Reports
    Replies: 1
    Last Post: 02-02-2011, 08:59 AM
  2. Need help in setting up a DB construction
    By ClownKiller in forum Database Design
    Replies: 5
    Last Post: 01-06-2011, 06:21 PM
  3. Setting value of a formfield
    By toddbuckles in forum Programming
    Replies: 7
    Last Post: 12-27-2010, 09:46 PM
  4. Setting Value for Each Row in Subform
    By swimmermx in forum Forms
    Replies: 11
    Last Post: 07-21-2010, 05:25 PM
  5. Setting up new database
    By mduplantis in forum Database Design
    Replies: 1
    Last Post: 06-23-2010, 11:07 AM

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