Results 1 to 9 of 9
  1. #1
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544

    Expr1: Expr2: etc. appearing in queries

    Hello everyone!

    I keep getting these "broken" queries.

    Code:
    SELECT Account.Date AS Expr1, DatePart("m",[Date]) AS M, DatePart("yyyy",[Date]) AS Y, Account.Owner AS Expr2, Account.DBAmt AS Expr3, Account.CRAmt AS Expr4
    FROM Account
    WHERE (((DatePart("m",[Date]))<DatePart("m",[Forms]![AReports]![SDate])) AND ((DatePart("yyyy",[Date]))=DatePart("yyyy",[Forms]![AReports]![SDate]))) OR (((DatePart("yyyy",[Date]))<DatePart("yyyy",[Forms]![AReports]![SDate])));
    Where it should be:


    Code:
    SELECT Account.Date, DatePart("m",[Date]) AS M, DatePart("yyyy",[Date]) AS Y, Account.Owner, Account.DBAmt, Account.CRAmt
    FROM Account
    WHERE (((DatePart("m",[Date]))<DatePart("m",[Forms]![AReports]![SDate])) AND ((DatePart("yyyy",[Date]))=DatePart("yyyy",[Forms]![AReports]![SDate]))) OR (((DatePart("yyyy",[Date]))<DatePart("yyyy",[Forms]![AReports]![SDate])));
    I thought it was happening when I disconnected the backend from the front end, but that isn't the case (it happened without disconnecting as well). Has anyone had this experience? Is there a reason and/or solution? Is it corruption?

    Thank you! Hope you're having a beautiful day!

  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
    I've definitely had this happen with split databases where for whatever reason the external connection is 'broken' when trying to run the query.
    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
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    and check the field labels in the queries:

    EXPR1: field, EXPR2: field,

    Account.Owner AS Expr2, Account.DBAmt AS Expr3

  4. #4
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Hi, Gina.

    Another thing that will cause this behavior is if the table name was changed. Example would be if table "Accounts" was renamed to "Account" (no 's' at the end).


    BTW, "Date" is a reserved word (and a built in function) in Access and shouldn't be used for an object name.
    See Problem names and reserved words in Access

  5. #5
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    Thanks Steve! No table names have been changed. I inherited the db and am waiting for them to approve a new one so I can eliminate the poor data structure and field name problems. :-) Hope you are well.

  6. #6
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    Thanks ranman, if I'm following what you're saying, the db does that itself (
    Owner AS Expr2, Account.DBAmt AS Expr3
    ). Not sure what else I should check? Thanks again!

  7. #7
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    you can name it whatever you wish. Change Expr1 to MyField1, or whatever.

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    I'm leaning towards what's in post 4. What would seem to be the mixing of the use of the word "date" (syntax) may be making it even worse. Sometimes it seems it's a field, yet there's no form reference.
    DatePart("m",[Date]))<DatePart("m",[Forms]![AReports]![SDate]

    If that is the case and this is a query, it cannot know what [Date] is. If it's vba constructed sql, that might explain why nothing was said about parameter prompts.If the table field is named Date, the syntax should be Account.[Date], not Account.Date. IMHO, the best thing to do in this new db is make sure no objects used reserved words, assuming this db isn't worth fixing if it's being replaced.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    As Colin said, any time the query can't find one of the tables in the query, Access automatically adds "AS ExprX" (where "X" is a number) as the name of the column in the query when looking at the query in SQL view.
    In SQL view, all you need to do if the table is a valid table) is delete the "AS ExprX". In design view, you would need to delete "ExprX:".

    This behavior also happens if the name of a field is not found in the the query table(s).

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

Similar Threads

  1. Only certain fields appearing in lookup
    By ryanmce92 in forum Forms
    Replies: 6
    Last Post: 05-22-2015, 05:12 PM
  2. Replies: 8
    Last Post: 01-02-2015, 06:44 PM
  3. Query sum is not appearing
    By trident in forum Queries
    Replies: 3
    Last Post: 12-15-2014, 06:23 AM
  4. Replies: 1
    Last Post: 09-05-2012, 01:36 PM
  5. Replies: 2
    Last Post: 08-19-2010, 09:33 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