Results 1 to 6 of 6
  1. #1
    aaron47 is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    11

    Question Can someone tell me why I get error message code 3071 (This expression is typed incorrectly...)?

    on this query?

    SELECT qryEmployeeHoursXLSWithLCDesc.LABORCATEGORY, qryEmployeeDataXLS.Expr1, qryEmployeeDataXLS.[PERSONNEL SURNAME], qryEmployeeDataXLS.[PERSONNEL FORNAME] AS Expr2, qryEmployeeHoursXLSWithLCDesc.REVIEWED, Sum(qryEmployeeHoursXLSWithLCDesc.FRIDAY) AS SumOfFRIDAY, Right$([laborcategory],2) AS LC, qryEmployeeHoursXLSWithLCDesc.LaborCategoryDesc
    FROM qryEmployeeDataXLS LEFT JOIN qryEmployeeHoursXLSWithLCDesc ON qryEmployeeDataXLS.[PERSONNEL ID NR] = qryEmployeeHoursXLSWithLCDesc.[PERSONNEL ID NR]
    GROUP BY qryEmployeeHoursXLSWithLCDesc.LABORCATEGORY, qryEmployeeDataXLS.Expr1, qryEmployeeDataXLS.[PERSONNEL SURNAME], qryEmployeeDataXLS.[PERSONNEL FORNAME], qryEmployeeHoursXLSWithLCDesc.REVIEWED, Right$([laborcategory],2), qryEmployeeHoursXLSWithLCDesc.LaborCategoryDesc
    HAVING (((qryEmployeeDataXLS.Expr1) In ((qryEmployeeHoursXLSWithLCDesc.REVIEWED) Between [Forms]![frmReportSelector]![txtDateStart] And [Forms]![frmReportSelector]![txtDateEnd])))


    ORDER BY qryEmployeeHoursXLSWithLCDesc.LABORCATEGORY, qryEmployeeDataXLS.Expr1, qryEmployeeDataXLS.[PERSONNEL SURNAME], qryEmployeeDataXLS.[PERSONNEL FORNAME], qryEmployeeHoursXLSWithLCDesc.REVIEWED;

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Two thoughts, both in the HAVING clause. I don't know that you can use IN() that way; I'd use a join between those tables. You also haven't specified the field the Between is to apply to (or the In should have referred to something else).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    aaron47 is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    11
    I have inherited thie database this query is in and I just realized that the items referenced in the HAVING clause are not different tables but columns within two different tables. I'm still trying to learn the nuances of Access but I believe that as a result, neither keyword (in or join) is actually correct. I am thinking that the 'having' keyword should be changed to the 'where' keyword with the second item as the field to which the 'between' keyword would apply. What do you think?

  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,518
    It's not your problem, but certainly a WHERE clause may be more appropriate (it would be after the FROM clause). The WHERE clause is evaluated before the aggregation, the HAVING clause after. The WHERE clause is typically the most appropriate and most efficient; the HAVING appropriate for things like when you want the customers having total sales of more than 1000 (HAVING Sum(Amount) > 1000).

    How would you describe in words what you're trying to accomplish with the criteria?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    aaron47 is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    11
    I got the report using the query above to work by changing the HAVING clause to a WHERE clause and moving the WHERE clause to after the FROM clause. The database where the query above is contained is being used by my project manager to track the hours our project group is charging to our assigned project. The query in question is used in a report that for each possible labor category and employee level, the total number of hours charged are produced.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Glad you got it sorted. Presumably you also changed the text of the SQL, as it appeared invalid as it was.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 2
    Last Post: 05-25-2013, 09:16 PM
  2. Replies: 5
    Last Post: 10-03-2012, 12:41 PM
  3. Replies: 1
    Last Post: 05-24-2012, 12:34 PM
  4. This expression is typed incorrectly
    By Ray67 in forum Queries
    Replies: 9
    Last Post: 01-03-2012, 12:53 PM
  5. Replies: 3
    Last Post: 03-31-2011, 11:07 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