Results 1 to 10 of 10
  1. #1
    u156531 is offline Novice
    Windows 10 Office 365
    Join Date
    Nov 2023
    Posts
    4

    I'm getting thi error on existing queries

    I'm getting this error below on existing MS Access queries. Can someone please explain why this is happening? I've included the SQL to one of the queries.

    This expression is typed incorrectly, or it is too complex to be evaluated. For example, a numeric expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to variables. (Error 3071)


    SELECT CInt(Mid([qrySelectDates].[monthyear],InStr([qrySelectDates].[monthyear],"/")+1,10)) AS [Year], Int((Mid([qrySelectDates].[monthyear],1,InStr([qrySelectDates].[monthyear],"/")-1))) AS [month], qrySelectDates.MonthYear, Nz([Failures],0) AS MaterialFailures, Eval("forms!frmAdmin!cboMaterial.column(2)") AS Population, qryIRSOutagesbyMonth.IRSOutages, Null AS Gate, 0 AS Occurances, 0 AS Computation
    FROM (qrySelectDates LEFT JOIN qryFailures ON qrySelectDates.MonthYear = qryFailures.MonthYear) LEFT JOIN qryIRSOutagesbyMonth ON qrySelectDates.MonthYear = qryIRSOutagesbyMonth.MonthYear


    ORDER BY CInt(Mid([qrySelectDates].[monthyear],InStr([qrySelectDates].[monthyear],"/")+1,10)), Int((Mid([qrySelectDates].[monthyear],1,InStr([qrySelectDates].[monthyear],"/")-1)));

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,929
    Usually that is down to your data - typically an unhandled null value

  3. #3
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,422
    Prime suspect for that: conversion functions such as Int, Cint, etc. will fail if passed a null or zls. You may want to have vba construct your sql after it handles nulls.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    u156531 is offline Novice
    Windows 10 Office 365
    Join Date
    Nov 2023
    Posts
    4
    Can someone show me how to correct the above error in this SQL.

    SELECT Count(FailureReport.ID) AS Failures, FailureReport.equipmentclass AS [C, J, orT?], FailureReport.equipmentclass, Month([DateFailure]) & "/" & Year([DateFailure]) AS MonthYear
    FROM FailureReport
    WHERE (((FailureReport.datefailure)>=[forms]![frmAdmin]![StartDate] And (FailureReport.datefailure)<=[forms]![frmAdmin]![EndDate]))
    GROUP BY FailureReport.equipmentclass, Month([DateFailure]) & "/" & Year([DateFailure]), FailureReport.equipmentclass
    HAVING (((FailureReport.equipmentclass)=Eval("forms!frmAd min!cboMaterial.column(1)")));

  5. #5
    u156531 is offline Novice
    Windows 10 Office 365
    Join Date
    Nov 2023
    Posts
    4
    I forgot to mention that if I remove the Having clause I don't get the error.

  6. #6
    madpiet is online now Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    565
    HAVING clause is for filtering aggregated data (like SUMS etc).

    should be ANDed to the existing WHERE clause:

    AND FailureReport.equipmentclass = Forms!frmAdmin!cboMaterial.column(1);

  7. #7
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,422
    I don't think you can get a combo column in sql without Eval.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    u156531 is offline Novice
    Windows 10 Office 365
    Join Date
    Nov 2023
    Posts
    4
    If I remove the Having clause the SQL runs without the error. After that I moved it to the where clause and I got the error again. I'm confused as to what is causing that error message or how to resolve it. The SQL used to work at some point in time but not any longer.

  9. #9
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,422
    I would try replacing this with a valid value to see what happens:
    Eval("forms!frmAd min!cboMaterial.column(1)"
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    Or even concatenate it to see the actual value with a Debug.Print?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Replies: 1
    Last Post: 02-23-2023, 04:05 PM
  2. change default value within an existing table - error 3219
    By markjkubicki in forum Programming
    Replies: 3
    Last Post: 09-01-2022, 10:11 AM
  3. Replies: 5
    Last Post: 07-14-2018, 07:22 AM
  4. Field F9 error when importing Excel file to existing table
    By dougdrex in forum Import/Export Data
    Replies: 2
    Last Post: 12-26-2014, 01:38 PM
  5. Replies: 2
    Last Post: 06-08-2014, 10:23 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