Results 1 to 8 of 8
  1. #1
    jgelpi16 is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544

    VBA/SQL Join Error

    I think I just need another set of eyes taking a look at this. I'm executing the below SQL in a module. I keep getting a "Syntax error in JOIN operation." error with "QRY_SEL_D100_DATA_TM_D.GROUP" highlighted at the beginning of the SELECT statement. Any suggestions would be much appreciated.



    Code:
        lngCatID = 9
        dtMonthBeg = funDataDate()
        strMonth = UCase(Format(dtMonthBeg, "mmm"))
        lngMonthIndex = DLookup("LOOKUP_ID", "TBL_LOOKUP_VALUES", "[LOOKUP_DESC] = '" & strMonth & "'")
        strLevel = "D"    
    mySQL = "INSERT INTO TBL_RESULTS ( [GROUP], REGION, DISTRICT, CATEGORY, LEVEL_FLAG, RESULTS_MONTH, RESULTS_MONTH_BEG, " & _
            "MONTH_RESULTS, YTD_RESULTS ) " & _
            "SELECT QRY_SEL_D100_DATA_TM_" & strLevel & ".GROUP, QRY_SEL_D100_DATA_TM_" & strLevel & ".REGION, " & _
            "QRY_SEL_D100_DATA_TM_" & strLevel & ".DISTRICT, " & lngCatID & ", '" & strLevel & "', " & lngMonthIndex & ", #" & dtMonthBeg & "#, " & _
            "IIf(Month([QRY_SEL_D100_DATA_TM_" & strLevel & "]![Month_Begin])=9," & _
            "([QRY_SEL_D100_DATA_TM_" & strLevel & "]![D100_YTD_TY])/([QRY_SEL_D100_DATA_TM_" & strLevel & "]![STORE_SALES_YTD_TY])," & _
            "([QRY_SEL_D100_DATA_TM_" & strLevel & "]![D100_YTD_TY]-[QRY_SEL_D100_DATA_LM_" & strLevel & "]![D100_YTD_TY])/" & _
            "([QRY_SEL_D100_DATA_TM_" & strLevel & "]![STORE_SALES_YTD_TY]-[QRY_SEL_D100_DATA_LM_" & strLevel & "]![STORE_SALES_YTD_TY])), " & _
            "[QRY_SEL_D100_DATA_TM_" & strLevel & "]![D100_YTD_TY]/[QRY_SEL_D100_DATA_TM_" & strLevel & "]![STORE_SALES_YTD_TY] " & _
            "FROM QRY_SEL_D100_DATA_TM_" & strLevel & ", QRY_SEL_D100_DATA_LM_" & strLevel & " INNER JOIN QRY_SEL_D100_DATA_LM_" & strLevel & " " & _
            "ON QRY_SEL_D100_DATA_TM_" & strLevel & ".DISTRICT = QRY_SEL_D100_DATA_LM_" & strLevel & ".DISTRICT;"
        CurrentDb.Execute mySQL, dbFailOnError

  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,652
    I would use this method to check the finished SQL:

    http://www.baldyweb.com/ImmediateWindow.htm

    offhand, you probably need to bracket group everywhere since its a reserved word. Post the SQL here if you don't see the problem.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jgelpi16 is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Of course! I didn't think of the fact that Group is a reserved word! Thank you.

  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,652
    No problem! It was fresh in my mind because I recently worked on a client db and ran into that, as they used group as a field name.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    jgelpi16 is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Quote Originally Posted by pbaldy View Post
    I would use this method to check the finished SQL:

    http://www.baldyweb.com/ImmediateWindow.htm

    offhand, you probably need to bracket group everywhere since its a reserved word. Post the SQL here if you don't see the problem.
    Unfortunately this didn't work. I'm still experiencing the same error. When I copy/paste the SQL into a query this is what I experience...

    SQL:
    Code:
    INSERT INTO TBL_RESULTS ( [GROUP], REGION, DISTRICT, CATEGORY, LEVEL_FLAG, RESULTS_MONTH, RESULTS_MONTH_BEG, MONTH_RESULTS, YTD_RESULTS ) SELECT QRY_SEL_D100_DATA_TM_D.[GROUP], QRY_SEL_D100_DATA_TM_D.REGION, QRY_SEL_D100_DATA_TM_D.DISTRICT, 9, 'D', 17, #9/1/2014#, IIf(Month([QRY_SEL_D100_DATA_TM_D]![Month_Begin])=9,([QRY_SEL_D100_DATA_TM_D]![D100_YTD_TY])/([QRY_SEL_D100_DATA_TM_D]![STORE_SALES_YTD_TY]),([QRY_SEL_D100_DATA_TM_D]![D100_YTD_TY]-[QRY_SEL_D100_DATA_LM_D]![D100_YTD_TY])/([QRY_SEL_D100_DATA_TM_D]![STORE_SALES_YTD_TY]-[QRY_SEL_D100_DATA_LM_D]![STORE_SALES_YTD_TY])), [QRY_SEL_D100_DATA_TM_D]![D100_YTD_TY]/[QRY_SEL_D100_DATA_TM_D]![STORE_SALES_YTD_TY] FROM QRY_SEL_D100_DATA_TM_D, QRY_SEL_D100_DATA_LM_D INNER JOIN QRY_SEL_D100_DATA_LM_D ON QRY_SEL_D100_DATA_TM_D.DISTRICT = QRY_SEL_D100_DATA_LM_D.DISTRICT;
    Click image for larger version. 

Name:	12-2-2014 4-09-01 PM.jpg 
Views:	5 
Size:	130.9 KB 
ID:	18926Click image for larger version. 

Name:	12-2-2014 4-09-21 PM.jpg 
Views:	5 
Size:	94.5 KB 
ID:	18927

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    If I'm reading that right that you have

    FROM TableA, TableB INNER JOIN TableB ON...

    It should be

    FROM TableA INNER JOIN TableB ON...
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    jgelpi16 is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    That did it. Thank you!

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. ambiguous join query error
    By Helystra in forum Queries
    Replies: 3
    Last Post: 10-24-2013, 11:10 AM
  2. Join Key Error Using Form
    By burrina in forum Forms
    Replies: 1
    Last Post: 12-08-2012, 06:44 PM
  3. Join Error
    By snowboarder234 in forum Database Design
    Replies: 11
    Last Post: 09-19-2011, 09:03 PM
  4. Ambiguous Outer Join Error
    By scruiks in forum Queries
    Replies: 3
    Last Post: 07-18-2010, 05:06 PM
  5. Error on Multiple Table Join & IIF
    By cmartin in forum Queries
    Replies: 1
    Last Post: 05-21-2010, 08:58 PM

Tags for this Thread

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