1 year ago

#73009

test-img

EKnoebel

Docmd Where Clause with IN clause and = operator

I'm using a docmd to open a report in ms access.

This command works as expected:

Docmd.OpenReport "rptCustomerProject", acViewReport, , "ProjectStatusID IN ([TempVars]![StatusActive], [TempVars]![StatusCompleted], [TempVars]![StatusPending]"

This command also works as expected:

Docmd.OpenReport "rptCustomerProject", acViewReport, , "CompanyOrgID = " & cboCompany

My problem occurs when I try and combine the two where clauses into one. I get a

Run-time error '13': Type mismatch.

I've tried various formatting but can't figure it out.

Docmd.OpenReport "rptCustomerProject", acViewReport, , "CompanyOrgID = " & cboCompany AND "ProjectStatusID IN ([TempVars]![StatusActive], [TempVars]![StatusCompleted], [TempVars]![StatusPending]"

Thanks in advance.

I made the changes and the Type mismatch error disappeared, however the ProjectStatusID no longer works.

I originally included the Where clause in the reports record source, but it said it was too complicated to analyze, so I redid the Select statement in my record source and put the Where clause in the form that calls the report. Different buttons on the form have different Where clauses. This is the only one I can't get to work.

My Reports record source is:

SELECT * FROM (SELECT tblCompanyOrg.CompanyOrgID, tblCompanyOrg.CompanyOrg, tblCustomer.CustomerID, tblCustomer.CustPhone, tblCustomer.CustEmail, [CustFName] & " " & [CustLName] AS FullName FROM tblCompanyOrg INNER JOIN tblCustomer ON tblCompanyOrg.CompanyOrgID = tblCustomer.CompanyOrgID)  AS q1 INNER JOIN (SELECT tbl2Project.ProjectID, tbl2Project.CustomerProjectID, tbl2Project.CustomerID, tbl2Project.ProjectStatusID FROM tbl2Project)  AS q2 ON q1.CustomerID = q2.CustomerID;

After several days of troubleshooting I have found the issue. My TempVars are either a numeric value or a null. When evaluating the where clause with just the ProjectStatusID IN (TempVars list) everything works fine. When I add an additional stipulation to the Where clause I get a Run-Time error ‘3071’ This expression is too complex to be evaluated. Setting my TempVars that are Null to 0 solves the problem. My ProjectStatusID field is an autonumbered field and doesn’t contain a value of 0. Another solution I found was to build a string variable and only assign TempVars that are not Null to it. As far as the original question was asked, braX did provide the solution. Thanks to all.

vba

ms-access

0 Answers

Your Answer

Accepted video resources