Hi,
I have a problem with, I hope, a simple solution that I'm just not seeing.
I have an Access 2010 database that runs a whole bunch of queries that are generated on the fly in VBA. It's throwing an error, and I can't figure out why. When I debug.print the sql statement that's generated and copy it to a query, the error is, "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."
The generated SQL that's throwing the error is as follows:
I've tried with both WHERE and HAVING. No joy. I've tried removing each individual column in design view, and no single column appears to be the culprit.
LIST_MiscDropDowns is a table. qryREPORT_UniversalQuestionsForCurrentReport is a query (see below). LIST_MiscDropDowns.FieldOption and qryREPORT_UniversalQuestionsForCurrentReport.InitialContact are both Text fields.
Here's where it gets a little complicated. When the underlying form that's running the code (that generates the above query) is open, qryREPORT_UniversalQuestionsForCurrentReport runs just fine. But just in case, here is the SQL for qryREPORT_UniversalQuestionsForCurrentReport:
ClientUniversalQuestions, Clients, and META_ReportGrantType are all tables. InitalContact (which is referenced in the generated query) is a column in the ClientUniversalQuestions table. qryREPORT_FilterLocationCriteria and qryREPORT_FilterOfficeLocation are queries.
Here's the SQL for qryREPORT_FilterLocationCriteria:
...and here's the SQL for qryREPORT_FilterOfficeLocation:
I've tried adding parameters to those queries, but that actually makes the problem worse, because when the fields are blank, it returns no rows.
Anybody see anything? Many thanks!
Katie
I have a problem with, I hope, a simple solution that I'm just not seeing.
I have an Access 2010 database that runs a whole bunch of queries that are generated on the fly in VBA. It's throwing an error, and I can't figure out why. When I debug.print the sql statement that's generated and copy it to a query, the error is, "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."
The generated SQL that's throwing the error is as follows:
SQL:
INSERT INTO REPORTS_Data ( ReportRunID, ReportDesignOptionID, Label, OptionCount )
SELECT 28 AS ReportRunID, 1 AS ReportDesignOptionID, Nz([OptionDescription],[FieldOption]) AS Label, Count(qryREPORT_UniversalQuestionsForCurrentReport.ClientID) AS CountOfClientID
FROM LIST_MiscDropDowns LEFT JOIN qryREPORT_UniversalQuestionsForCurrentReport ON LIST_MiscDropDowns.FieldOption = qryREPORT_UniversalQuestionsForCurrentReport.InitialContact
WHERE (((LIST_MiscDropDowns.FieldName)='Initial Contact') AND ((LIST_MiscDropDowns.IsActive)=True))
GROUP BY 28, 1, Nz([OptionDescription],[FieldOption]), LIST_MiscDropDowns.SortOrder
ORDER BY LIST_MiscDropDowns.SortOrder;
I've tried with both WHERE and HAVING. No joy. I've tried removing each individual column in design view, and no single column appears to be the culprit.
LIST_MiscDropDowns is a table. qryREPORT_UniversalQuestionsForCurrentReport is a query (see below). LIST_MiscDropDowns.FieldOption and qryREPORT_UniversalQuestionsForCurrentReport.InitialContact are both Text fields.
Here's where it gets a little complicated. When the underlying form that's running the code (that generates the above query) is open, qryREPORT_UniversalQuestionsForCurrentReport runs just fine. But just in case, here is the SQL for qryREPORT_UniversalQuestionsForCurrentReport:
SQL:
SELECT ClientUniversalQuestions.*, Clients.SpecificCounty
FROM (((Clients INNER JOIN ClientUniversalQuestions ON Clients.ClientID = ClientUniversalQuestions.ClientID) INNER JOIN META_ReportGrantType ON Clients.GrantType = META_ReportGrantType.GrantType) INNER JOIN qryREPORT_FilterLocationCriteria ON Clients.ClientID = qryREPORT_FilterLocationCriteria.ClientID) INNER JOIN qryREPORT_FilterOfficeLocation ON Clients.ClientID = qryREPORT_FilterOfficeLocation.ClientID
WHERE (((Clients.DateCreated) Between GetBeginDate() And GetEndDate()));
Here's the SQL for qryREPORT_FilterLocationCriteria:
SQL:
SELECT Clients.ClientID
FROM Clients
WHERE (((Clients.OverallCounty)="City of Madison") AND (([Forms]![frmMonthlyReportCriteria]![cboLocationCriteria])="Madison")) OR ((([Forms]![frmMonthlyReportCriteria]![cboLocationCriteria]) Is Null Or ([Forms]![frmMonthlyReportCriteria]![cboLocationCriteria])="All"));
...and here's the SQL for qryREPORT_FilterOfficeLocation:
SQL:
SELECT Clients.ClientID
FROM Clients
WHERE (((Clients.FromOtherDatabase)=[Forms]![frmMonthlyReportCriteria]![cboOfficeLocCriteria]) AND (([Forms]![frmMonthlyReportCriteria]![cboOfficeLocCriteria]) Is Not Null And ([Forms]![frmMonthlyReportCriteria]![cboOfficeLocCriteria])<>"Main")) OR (((Clients.FromOtherDatabase) Is Null) AND (([Forms]![frmMonthlyReportCriteria]![cboOfficeLocCriteria])="Main")) OR ((([Forms]![frmMonthlyReportCriteria]![cboOfficeLocCriteria]) Is Null Or ([Forms]![frmMonthlyReportCriteria]![cboOfficeLocCriteria])="All"));
I've tried adding parameters to those queries, but that actually makes the problem worse, because when the fields are blank, it returns no rows.
Anybody see anything? Many thanks!
Katie