@Micron,
If a <> b will result in FALSE if either a or b is null. No test of a null value will ever return true except IsNull()
@Kitty,
Do not use parentheses unless they are needed. Having them in an expression just causes confusion when they are serving no purpose.
If ([Mid] <> "aaa") And ([Mst] = "bbb") And ([M1] <> [M2]) Then strDocName = "Report"
should be
If [Mid] <> "aaa" And [Mst] = "bbb" And [M1] <> [M2] Then strDocName = "Report"
Also, don't use square brackets for the same reason. They are simply eye clutter and distracting.
Now we get to the rules of precedence which is what you need to understand to create compound conditions. In logical operations the order is NOT, AND, OR
If all the conditions use the same relational operator
either:
a and b and c and d
OR:
a or b or c or d
Then the order is irrelevant. The result will be the same regardless of the order in which the conditions are evaluated. a and b is exactly the same result as b and a.
The tricky part is when you need to mix operators.
a or b and c or d
Now we have to perform the conditions based on the order of precedence so AND happens first. To explain this, I will add parentheses to show how the statement is evaluated
a or (b and c) or d
Once the AND is handled, we now have three values instead of four and they are related by OR since we evaluated the AND away.
Rather than depend on you or your readers understanding how the compiler will evaluate complex expressions, it is best to always use parentheses when you use different operators. Perhaps you wanted
a or b and c or d
to be evaluated as
(a or b) and (c or d)
That would most likely give a different result than the default interpretation. Or how about:
((a or b) and c) or d
As you can see, there are several different results and only YOU know what you want.