Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228

    Runtime error 3075

    I have previously had some very similar code working. I can't figure out what the problem is with this one (see below):

    syntax error (missing operator) in query expression.

    Code:
    Private Sub Command37_Click()
    Dim Permits As String
    Dim db As Database
    Set db = CurrentDb
    Dim rst As DAO.Recordset
    Permits = "SELECT DISTINCT Site_Risks.selected, PERMIT_LIST.PERMIT_NAME, PPE_LIST.PPE_LIST"
    Permits = Permits & "FROM (PPE_LIST INNER JOIN (PERMIT_LIST INNER JOIN Site_Risk_Categories ON PERMIT_LIST.PERMIT_ID = Site_Risk_Categories.Permit_ID) ON PPE_LIST.PPE_ID = Site_Risk_Categories.PPE_ID) INNER JOIN Site_Risks ON Site_Risk_Categories.Risk_category_ID = Site_Risks.Category_ID"
    Permits = Permits & "WHERE (((Site_Risks.selected)=True));"
    Set rst = db.OpenRecordset(Permits)
    
    
    End Sub
    A difference between this and the other working code is this code can return multiple values. The other time I used it, it was for one record only. I'm not sure that is the issue but its worth mentioning. More likely its some formatting issue with the code.
    the error highlights this line:


    Set rst = db.OpenRecordset(sSql)

    any thoughts appreciated as I'm stumped.

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,826
    You aren't using spaces between key words so one of your results will be PPE_LIST.PPE_LISTPermits = PermitsFROM
    Get in the habit of having the space at the end or beginning of a line and be consistent with the choice. That should help.
    This would likely be obvious if you also adopted the habit of printing the sql variable to the immediate window for review during testing or when it fails.
    Last edited by Micron; 12-18-2019 at 09:36 AM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    I knew it would be something simple. Also thanks for the advice. Thanks a lot!

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,826
    You're welcome. For the benefit of others who might not be familiar with that style of concatenation (which I prefer over line continuation) or printing to the immediate window here's your adapted code as an example:
    Code:
    Permits = "SELECT DISTINCT Site_Risks.selected, PERMIT_LIST.PERMIT_NAME, PPE_LIST.PPE_LIST FROM "
    Permits = Permits & "(PPE_LIST INNER JOIN (PERMIT_LIST INNER JOIN Site_Risk_Categories ON PERMIT_LIST.PERMIT_ID = "
    Permits = Permits & "Site_Risk_Categories.Permit_ID) ON PPE_LIST.PPE_ID = Site_Risk_Categories.PPE_ID) INNER JOIN "
    Permits = Permits & "Site_Risks ON Site_Risk_Categories.Risk_category_ID = Site_Risks.Category_ID WHERE " 
    Permits = Permits & "(((Site_Risks.selected)=True));"
    Debug.Print Permits
    When no longer needed, comment out the Debug.Print line
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I, too, prefer concatenation over line continuation.
    But I have the spaces at the beginning of the line instead of the end.
    I also have the SQL keywords at the beginning of the line and, if a clause is really long, I sometimes add blank lines for readability.
    Code:
    Permits = "SELECT DISTINCT Site_Risks.selected, PERMIT_LIST.PERMIT_NAME, PPE_LIST.PPE_LIST"
    
    Permits = Permits & " FROM (PPE_LIST INNER JOIN (PERMIT_LIST INNER JOIN Site_Risk_Categories ON PERMIT_LIST.PERMIT_ID ="
    Permits = Permits & " Site_Risk_Categories.Permit_ID) ON PPE_LIST.PPE_ID = Site_Risk_Categories.PPE_ID) INNER JOIN"
    Permits = Permits & " Site_Risks ON Site_Risk_Categories.Risk_category_ID = Site_Risks.Category_ID" 
    
    Permits = Permits & " WHERE (((Site_Risks.selected)=True));"
    '  Permits = Permits & " WHERE (((Site_Risks.selected)=False));"
    Debug.Print Permits
    It is also easier to comment out a line to try a different line. (see the WHERE lines)



    Note: the Blue highlighting isn't available in the IDE. It is here just for emphasis.

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

Similar Threads

  1. Runtime Error 3075
    By DMT Dave in forum Access
    Replies: 3
    Last Post: 12-06-2019, 05:14 AM
  2. Runtime error 3075
    By Thompyt in forum Programming
    Replies: 2
    Last Post: 11-21-2017, 04:43 PM
  3. runtime error 3075
    By Compufreak in forum Access
    Replies: 3
    Last Post: 08-14-2012, 01:40 AM
  4. RunTime error 3075
    By Compufreak in forum Access
    Replies: 3
    Last Post: 07-25-2012, 02:18 AM
  5. Runtime 3075 error
    By whm1 in forum Programming
    Replies: 4
    Last Post: 03-24-2010, 02:50 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