Emil Olsen
Emil Olsen

Reputation: 352

How to make an access query criteria OR statement active only when a parameter has certain values?

I have this query:

SELECT t_Data.ID, t_Data.Location, t_Data.[VG's], t_Data.BinSize, t_Data.Date, t_Data.Time, t_Data.RPM001, t_Data.POW001, t_Data.WSP001, t_Data.YAW001, t_Data.RPM002, t_Data.POW002, t_Data.WSP002, t_Data.YAW002
FROM t_Data
WHERE (((t_Data.Location)=[Forms]![f_Main]![LocationCombo]) AND ((t_Data.BinSize)=[Forms]![f_Main]![BinSizeCombo]) AND ((t_Data.POW001)>[Forms]![f_Main]![LowerLimit] And (t_Data.POW001)<[Forms]![f_Main]![UpperLimit]) AND ((t_Data.WSP001)>[Forms]![f_Main]![LowerLimitMs_Text] And (t_Data.WSP001)<[Forms]![f_Main]![UpperLimitMs_Text] And (t_Data.WSP001)>[Forms]![f_Main]![LowerLimitMs_Text] And (t_Data.WSP001)<[Forms]![f_Main]![UpperLimitMs_Text]) AND ((t_Data.YAW001)>=Sector1_dsp() And (t_Data.YAW001)<=Sector2_dsp()) AND ((t_Data.POW002)>[Forms]![f_Main]![LowerLimit_Text] And (t_Data.POW002)<[Forms]![f_Main]![UpperLimit_Text] And (t_Data.POW002)>[Forms]![f_Main]![LowerLimit_Text] And (t_Data.POW002)<[Forms]![f_Main]![UpperLimit_Text]) AND ((t_Data.WSP002)>[Forms]![f_Main]![LowerLimitMs_Text] And (t_Data.WSP002)<[Forms]![f_Main]![UpperLimitMs_Text] And (t_Data.WSP002)>[Forms]![f_Main]![LowerLimitMs_Text] And (t_Data.WSP002)<[Forms]![f_Main]![UpperLimitMs_Text]) AND ((t_Data.YAW002)>=Sector1_dsp() And (t_Data.YAW002)<=Sector2_dsp())) OR (((t_Data.Location)=[Forms]![f_Main]![LocationCombo]) AND ((t_Data.BinSize)=[Forms]![f_Main]![BinSizeCombo]) AND ((t_Data.POW001)>[Forms]![f_Main]![LowerLimit] And (t_Data.POW001)<[Forms]![f_Main]![UpperLimit]) AND ((t_Data.WSP001)>[Forms]![f_Main]![LowerLimitMs_Text] And (t_Data.WSP001)<[Forms]![f_Main]![UpperLimitMs_Text] And (t_Data.WSP001)>[Forms]![f_Main]![LowerLimitMs_Text] And (t_Data.WSP001)<[Forms]![f_Main]![UpperLimitMs_Text]) AND ((t_Data.YAW001)>=Sector3_dsp() And (t_Data.YAW001)<=Sector4_dsp()) AND ((t_Data.POW002)>[Forms]![f_Main]![LowerLimit_Text] And (t_Data.POW002)<[Forms]![f_Main]![UpperLimit_Text] And (t_Data.POW002)>[Forms]![f_Main]![LowerLimit_Text] And (t_Data.POW002)<[Forms]![f_Main]![UpperLimit_Text]) AND ((t_Data.WSP002)>[Forms]![f_Main]![LowerLimitMs_Text] And (t_Data.WSP002)<[Forms]![f_Main]![UpperLimitMs_Text] And (t_Data.WSP002)>[Forms]![f_Main]![LowerLimitMs_Text] And (t_Data.WSP002)<[Forms]![f_Main]![UpperLimitMs_Text]) AND ((t_Data.YAW002)>=Sector3_dsp() And (t_Data.YAW002)<=Sector4_dsp()));

The fields called YAW001 and YAW002 are the direction of a wind turbine.

I have a form with a function where it is possible to choose only wind from north, north is 0 degrees. East is 90 degrees.

The problem is that I have the limits working just fine as long as the angle is 0->360 degrees. When i choose to see fx a 90 degree windows from north, i need values that are between 360-90/2 and 360+90/2. I then get a criteria as:

Yaw001 > 315 AND Yaw001 < 405

But since the values needed are from 315 to 45 degrees, i have a problem. I need it to see that if the limit is above 360, the criteria should then be

Yaw001 > 315 OR Yaw001 < 45

How do i crack this one?

The same applies for Yaw002.

The system may also be rotated counter clockwise so that the desired values are

Yaw001 < -45 AND Yaw001 < 45

And again the lowest value is 0, so it would need to be

Yaw001 > 315 OR Yaw001 < 45

I have tried using this statement in OR:

IIf(Sector4_dsp()>360;<=Sector4_dsp()-360;<0)

But even if it is true, it does not return the criteria <=Sector4_dsp()-360.

I hope you follow me here.

Best regards, Emil.

Upvotes: 0

Views: 91

Answers (1)

Rhys Jones
Rhys Jones

Reputation: 5508

I don't have MSAccess to hand but surely the modulo operation would give you what you need? In your SQL query use (angle MOD 360). For example, (-45 MOD 360) = 315, (405 MOD 360) = 45.

Edit, adding sample condition expressions

Assuming an arc of 90 degrees either side of North;

direction = 0
min = (direction - 90/2 mod 360)
max = (direction + 90/2 mod 360)
Yaw001 = Yaw001 mod 360

then

(min <= max and Yaw001 >= min and Yaw001 =< max) or (min > max and (Yaw001 > min or Yaw001 < max)

Upvotes: 1

Related Questions