Brandon Patrick
Brandon Patrick

Reputation: 73

Access form DoCmd.ApplyFilter with If Statemnent

Is it possible to have an If statement contained within DoCmd.ApplyFilter?

I have a continuous form that includes the category columns EmployeeTypeID (1 (Field), 2 (Office)) and DepartmentID (1 (New Sales), 2(Service), 3(Other)). I want to be able to filter the DepartmentID to only show the records containing Other just for Office while showing all departments for Field.

DoCmd.ApplyFilter , "(dbo_Stat.DepartmentID)=3" 

That works to filter everything

DoCmd.AppplyFilter, "IF(dbo_Stat.EmployeeTypeID)=2 Then (dbo_Stat.DepartmentID)=3

That is what I want to achieve, however the syntax doesn't seem right. Is what I'm trying to do even possible?

Upvotes: 0

Views: 514

Answers (1)

Gustav
Gustav

Reputation: 55906

It is:

DoCmd.AppplyFilter, "dbo_Stat.DepartmentID = IIf(dbo_Stat.EmployeeTypeID = 2, 3, SomeOtherValueThan3)"

For a "match all", you could try the old trick:

DoCmd.AppplyFilter, "dbo_Stat.DepartmentID = IIf(dbo_Stat.EmployeeTypeID = 2, 3, dbo_Stat.DepartmentID)"

Upvotes: 1

Related Questions