Results 1 to 10 of 10
  1. #1
    Join Date
    May 2021
    Posts
    5

    Invalid syntax error on exisitng queries - unable to edit

    Hi,



    We are suddenly getting "the expression you entered contains invalid syntax" error on some existing queries which have not been amended. Once we click ok on the error message, the query shuts down so we cannot view or edit.

    Any ideas as to why this is happening?

    Many thanks

    R

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    This sort of thing is usually caused by program updates that introduce bugs, or the updates cause malformed code/expressions to no longer work. If it's happening on all pc's check the build and versions of Access on them and if recent, try rolling the update back on one and see what happens. You could also open the query in design view, copy and post the sql and maybe someone will spot something that's not quite right.
    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
    May 2021
    Posts
    5
    Quote Originally Posted by Micron View Post
    This sort of thing is usually caused by program updates that introduce bugs, or the updates cause malformed code/expressions to no longer work. If it's happening on all pc's check the build and versions of Access on them and if recent, try rolling the update back on one and see what happens. You could also open the query in design view, copy and post the sql and maybe someone will spot something that's not quite right.
    Many thanks for your reply. I get the same when I try and open in design view - error message displayed and then the query shuts immediately
    I will try rolling back updates.

  4. #4
    Join Date
    Apr 2017
    Posts
    1,679
    Did you open it in SQL View? Or only in default design view?

  5. #5
    Join Date
    May 2021
    Posts
    5
    Quote Originally Posted by ArviLaanemets View Post
    Did you open it in SQL View? Or only in default design view?
    I can't see SQL view, can only open in design view.

  6. #6
    CarlettoFed is offline Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Dec 2019
    Posts
    257
    If you attach a sample file we could check it directly and possibly advise you.

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    You cannot right click on the query name in the nav pane and get sql view option?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    Join Date
    Apr 2017
    Posts
    1,679
    Quote Originally Posted by Micron View Post
    You cannot right click on the query name in the nav pane and get sql view option?
    Haven't tried this, but maybe someone knows a script to read the querystring to variable, and display it (the querystring is a property of query, so it must be possible to read it). OP runs the the script and saves the querystring. Then finds out what is wrong, and makes corrections to querystring. Then renames old query, creates a new one, pasting corrected querystring into SQL view, and saves the new query with old one' s name. As last step, tests the app, and when all is OK, then deletes renamed old query.

    I myself can't help with this, as I am on sick leave, and I don't have Office installed at my home computer.

  9. #9
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    a script to read the querystring to variable
    to assign a query's sql to a variable is simply

    dim sqlstr as string
    sqlstr=currentdb.QueryDefs("name of query").SQL

    or just type
    ?currentdb.QueryDefs("name of query").SQL
    in the vba immediate window


    Appreciate you are saying you cannot open in design view but if you can, to view the sql, click on the design ribbon
    Click image for larger version. 

Name:	image_2023-11-30_090436307.png 
Views:	11 
Size:	20.3 KB 
ID:	51119

    or the bottom right of the access window
    Click image for larger version. 

Name:	image_2023-11-30_090608371.png 
Views:	11 
Size:	3.1 KB 
ID:	51120

    I would also check your vba library for missing references - open the vba window, click on Tools, then References
    Click image for larger version. 

Name:	image_2023-11-30_091427932.png 
Views:	11 
Size:	16.0 KB 
ID:	51121

    The first 3 are required as a minimum - you may have a different version number for the Object Library - the version number depends on the version of Access you are using

    Failing that, although very rare, it may be the query object has become corrupted - this can happen if multiple users are using the same front end. If that is the case, the solution is to revert to a backup of the front end. (I assume your db is split)

  10. #10
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Sigh, another false memory. It's not an option if you right click on a nav pane query name.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 14
    Last Post: 08-18-2023, 04:16 PM
  2. Invalid Syntax
    By Perfac in forum Reports
    Replies: 4
    Last Post: 11-28-2018, 09:56 AM
  3. Replies: 1
    Last Post: 06-22-2018, 05:53 PM
  4. Replies: 3
    Last Post: 07-12-2017, 04:29 PM
  5. Replies: 13
    Last Post: 12-05-2011, 05:10 AM

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