Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vba filter expression syntax

Status
Not open for further replies.

Prattdakota

Vendor
Jan 10, 2003
38
0
0
US
Hello - I'm having an issue with a filter to a recordset in my code. When I try to ensure the correct precedence by adding parenthesis I get an error. For example:

The following line works fine:

Code:
 .Filter = "TransPostFiscalYear = " & intFiscalYear & " AND (TransactionCode = 'ASST SURGEON') OR (TransactionCode = 'ATTENDNOTP')"

However, the following line of code, which is the same except for two parenthesis being removed, produces an error stating "Arguements are of the wrong type, are out of acceptable range, or are in conflict with one another"

Code:
 .Filter = "TransPostFiscalYear = " & intFiscalYear & " AND (TransactionCode = 'ASST SURGEON' OR TransactionCode = 'ATTENDNOTP')"

Seems odd to me that just forcing the precedence should have this effect. I'm out of ideas. If you have an idea for me to try I'd appreciate your insight.

Thanks

 
What about this ?
Code:
.Filter = "TransPostFiscalYear=" & intFiscalYear & " AND TransactionCode In ('ASST SURGEON','ATTENDNOTP')"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PH. Thanks very much for the suggestion. That was a good idea and I hadn't thought of it. Unfortunately it didn't seem to do the trick either. I also tried the following with the same resultant error message:

Code:
 .Filter = "TransactionCode In ('ASST SURGEON', 'ATTENDNOTP')"

I appreciate the suggestion.
 
I think when it builds it itself, you may need to add the FiscalYear more than once...

Code:
.Filter = ("TransPostFiscalYear = " & intFiscalYear & " AND TransactionCode = 'ASST SURGEON') OR ("TransPostFiscalYear = " & intFiscalYear & " AND TransactionCode = 'ATTENDNOTP')"

SeeThru
Synergy Connections Ltd - Telemarketing Services
 
Thanks for the reply SeeThru. Yes, I've resorted to just that type of coding which does seem to work. I actually have about a dozen transaction codes but just used two to illustrate the problem. I guess this is just one case where I'll make it work but never understand the cause of the error.

Thanks again,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top