Results 1 to 5 of 5
  1. #1
    max is offline Novice
    Windows XP Access 97
    Join Date
    Sep 2011
    Posts
    17

    SQL syntax error

    Hi I am getting the following error upon running some SQL in VBA

    Run-time error '3075':

    Syntax error (missing operator) in query expression
    'CurrentConfigurationQry.EvaseDiameterFROM (((FanIDTbl LEFT JOIN PrimaryLocationsQry ON FanIDTbl.FanIndexID = PrimaryLocationsQry.FanIndexID)LEFT JOIN PrimaryFanLocationsTbl ON (PrimaryLocationsQry.MaxOfDateOfMove = PrimaryFanLocationsTbl.DateOfMove) AND (PrimaryLocationsQry.FanIndexID =


    The code works in the query builder from where it was copied - the only modification has been the insertion of line breaks. The full SQL code is as follows:




    Set Rst2 = CurrentDb.OpenRecordset("SELECT FanIDTbl.FanIndexID, FanIDTbl.FanName, FanIDTbl.Type, PrimaryFanLocationsTbl.LocationID, PrimaryLocationsTbl.DuctDiameter, PrimaryLocationsTbl.TestPointElevation, PrimaryLocationsTbl.Location, PrimaryLocationsQry.MaxOfDateOfMove, CurrentConfigurationQry.MaxOfConfigurationDate, CurrentConfigurationQry.Solidity, CurrentConfigurationQry.NumberOfBlades, CurrentConfigurationQry.BladePitch, CurrentConfigurationQry.EvaseDiameter" & _

    "FROM (((FanIDTbl LEFT JOIN PrimaryLocationsQry ON FanIDTbl.FanIndexID = PrimaryLocationsQry.FanIndexID)" & _

    "LEFT JOIN PrimaryFanLocationsTbl ON (PrimaryLocationsQry.MaxOfDateOfMove = PrimaryFanLocationsTbl.DateOfMove) AND (PrimaryLocationsQry.FanIndexID = PrimaryFanLocationsTbl.FanIndexID))" & _

    "LEFT JOIN PrimaryLocationsTbl ON PrimaryFanLocationsTbl.LocationID = PrimaryLocationsTbl.LocationID)" & _

    "LEFT JOIN CurrentConfigurationQry ON PrimaryLocationsQry.FanIndexID = CurrentConfigurationQry.FanIndexID" & _

    "WHERE (((PrimaryLocationsTbl.Location)=[LocationName]) AND ((FanIDTbl.Current)=Yes) AND ((FanIDTbl.PrimaryFan)=Yes));", dbOpenSnapshot)


    Any help is much appreciated

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,965
    Need to have spaces in the SQL string so things don't run together when it compiles, as you can see is happening in the error message.

    " FROM ...

    " LEFT ...

    " LEFT ...

    " LEFT ...

    " WHERE ...
    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
    max is offline Novice
    Windows XP Access 97
    Join Date
    Sep 2011
    Posts
    17
    Hi, making progress -the syntax error is smaller now

    Run-time error '3075':

    Syntax error (missing operator) in query expression
    '(((PrimaryLocationsTbl.Location)=South Exhust) AND
    ((FanIDtbl.Current)=Yes) AND ((FanIDTbl.PrimaryFan)=Yes);',

    The code has been modified to

    Set Rst2 = CurrentDb.OpenRecordset("SELECT FanIDTbl.FanIndexID, FanIDTbl.FanName, FanIDTbl.Type, PrimaryFanLocationsTbl.LocationID, PrimaryLocationsTbl.DuctDiameter, PrimaryLocationsTbl.TestPointElevation, PrimaryLocationsTbl.Location, PrimaryLocationsQry.MaxOfDateOfMove, CurrentConfigurationQry.MaxOfConfigurationDate, CurrentConfigurationQry.Solidity, CurrentConfigurationQry.NumberOfBlades, CurrentConfigurationQry.BladePitch, CurrentConfigurationQry.EvaseDiameter " & _
    " FROM (((FanIDTbl LEFT JOIN PrimaryLocationsQry ON FanIDTbl.FanIndexID = PrimaryLocationsQry.FanIndexID) " & _
    " LEFT JOIN PrimaryFanLocationsTbl ON (PrimaryLocationsQry.MaxOfDateOfMove = PrimaryFanLocationsTbl.DateOfMove) AND (PrimaryLocationsQry.FanIndexID = PrimaryFanLocationsTbl.FanIndexID)) " & _
    " LEFT JOIN PrimaryLocationsTbl ON PrimaryFanLocationsTbl.LocationID = PrimaryLocationsTbl.LocationID) " & _
    " LEFT JOIN CurrentConfigurationQry ON PrimaryLocationsQry.FanIndexID = CurrentConfigurationQry.FanIndexID " & _
    " WHERE (((PrimaryLocationsTbl.Location)=" & LocationName & ") AND ((FanIDTbl.Current)=Yes) AND ((FanIDTbl.PrimaryFan)=Yes);", dbOpenSnapshot)

  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,530
    Try

    " WHERE PrimaryLocationsTbl.Location='" & LocationName & "' AND FanIDTbl.Current=Yes AND FanIDTbl.PrimaryFan=Yes;", dbOpenSnapshot)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    max is offline Novice
    Windows XP Access 97
    Join Date
    Sep 2011
    Posts
    17
    Success!! Thanks very much

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

Similar Threads

  1. Syntax Error
    By desk4tbc in forum Programming
    Replies: 3
    Last Post: 08-09-2011, 06:13 PM
  2. SQL Syntax Error
    By NoiCe in forum Queries
    Replies: 5
    Last Post: 04-01-2011, 11:43 AM
  3. Need help with Syntax Error
    By jgelpi16 in forum Programming
    Replies: 2
    Last Post: 02-04-2011, 08:34 AM
  4. Incomplete Syntax Clause (syntax error)
    By ajetrumpet in forum Programming
    Replies: 4
    Last Post: 09-11-2010, 10:47 AM
  5. Syntax error
    By smikkelsen in forum Access
    Replies: 6
    Last Post: 04-28-2010, 09:38 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