My code is as follows:
If (InStr(1, "ALL", Itype) Or InStr(1, Uvar.Device, Itype) _
And (InStr(1, "ALL", Isec) Or InStr(1, Uvar.Sec, Isec)) _
And (InStr(1, "ALL", Idev) Or InStr(1, Uvar.Model, Idev)) Then Useline = "TRUE"
To expand on this a bit:
Itype is a long string, e.g. –
Itype = All, Apple, Pear, OrangeIsec = dog, cat, duckIdev = tree, flower, plant
Each UVar.x is a single word, e.g. –
UVar.Device = AppleUVar.Sec = CatUVar.Model = tree
So, if Itype contains the string “All” or it contains the value of UVar.Device
and Isec also contains the string “All” or it contains the value of UVar.Sec
and IDev also contains the string “All” or it contains the value of UVar.Model
then I want to have the if statement = true.
My code above seems to return true whatever values are used, as long as at least one value criteria set matches.
Thus, do the strings IType, Idev and Isec each contain either the value “all” or a specific user defined value?
Well, for one thing, your code doesn’t compile – you either have to remove the opening parenthesis after the IF or add a matching closing parenthesis.
More importantly, though, you’ve got the order of the Instr() parameters mixed up. First is string to look IN, second is string to look FOR. That should solve it.
PS: While Brettdj’s answer is true, VBA will interpret the position 0 as false and any other as true, so that’s not necessarily the issue.