Results 1 to 7 of 7
  1. #1
    TerraEarth is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    86

    Unhappy Compile error from function in sql query - Was working before!

    The error: Compile error. in query expression 'MID(document,1,6)="XXXXXX'.



    The query:

    Code:
    SELECT * FROM qry_a
    WHERE 
    MID(document,1,6) = "XXXXXX";
    I'm completely lost. I was developing a program to generate PDFs with query values, after I had tested it several times one of my queries broke. I tried compacting and repairing but that did not fix anything either. This query was working just fine just an hour ago! Any idea?

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Is qry_a based on a table or another query. If the latter, look for fields like expr1 in the underlying queries which could occur due to your crash.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    TerraEarth is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    86
    qry_a is based on a series of inner joins between several tables. qry_a works just fine at the moment.

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Check there are no references marked as MISSING.
    I just tested on another users database with a missing reference and got an undefine function error using Mid in a query.
    Fixing that solved the issue.

    If that doesn't solve it, try another Access function such as Left or Nz and see if those work.
    If not I suggest running an Office repair
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    TerraEarth is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    86
    Quote Originally Posted by isladogs View Post
    Check there are no references marked as MISSING.
    I just tested on another users database with a missing reference and got an undefine function error using Mid in a query.
    Fixing that solved the issue.

    If that doesn't solve it, try another Access function such as Left or Nz and see if those work.
    If not I suggest running an Office repair
    I tried all of the above, no luck. What I ended up doing is rewriting all of my queries so I could avoid using a function such as MID in the query completely, though i wish I could figure out what went wrong . It was working just fine so I'm not sure what could have happened - corruption mayhaps?

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Corruption is certainly possible.
    See this link for my approach to such issues https://www.access-programmers.co.uk...7&postcount=12
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    document is a reserved word. If you must use it, surround with [ ]
    Maybe not the issue, but can't hurt to test if it is.
    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: 5
    Last Post: 02-21-2017, 01:58 PM
  2. Compile Error: Sub/Function not defined
    By TheKillerMonkey in forum Programming
    Replies: 12
    Last Post: 04-18-2016, 01:48 PM
  3. Compile Error Sub or function not defined
    By Ray67 in forum Reports
    Replies: 3
    Last Post: 07-02-2012, 04:11 PM
  4. Compile error: code or function not defined
    By GeorgeBrown in forum Access
    Replies: 1
    Last Post: 09-19-2011, 10:25 AM
  5. Compile error. Sub of function not defined
    By plavookins in forum Reports
    Replies: 7
    Last Post: 04-22-2011, 10:15 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