Solved

Access VBA Form - Filter Multiple and/or

Posted on 2016-11-11
7
36 Views
Last Modified: 2016-11-15
Hi,

I'm using Access 2010 and I have a form which I'd like to filter data.
I have two fields: ACCOUNT + CPYCODE

And I'd like to filter the data so we end up with:
CPYCODE = 12 - 14
ACCOUNT = Not like: A00090, A00091, A00092, A00093, A00094

I doubt a string of 'ACCOUNT not like' is the best way to do it, and I don't think my use of ( ) is correct either:

DoCmd.ApplyFilter , "(CpyCode = '12') or (CpyCode = '13') or (CpyCode = '14') and Account not like 'A00090'"

Open in new window


Can anyone help me achieve what I'm trying to do?

Many thanks,
0
Comment
Question by:Jack Marley
7 Comments
 
LVL 48

Expert Comment

by:Rgonzo1971
ID: 41883659
HI,

pls try
DoCmd.ApplyFilter , "((CpyCode = '12') or (CpyCode = '13') or (CpyCode = '14')) and Account not like 'A00090'"

Open in new window

Regards
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 41883660
How about something like:

CPYCODE = 12 - 14
ACCOUNT = Not like: A00090, A00091, A00092, A00093, A00094

strFilter = "[CPYCODE] IN ("12", "13", "14") AND NOT ([Account] IN ("A00090", "A00091", "A00092", "A00093", "A00094")

This assumes that [CPYCODE] is a string, as indicated by the single quotes surrounding '12' in your sample above.

HTH
Dale
0
 
LVL 48

Expert Comment

by:Rgonzo1971
ID: 41883663
corrected code
DoCmd.ApplyFilter , "((CpyCode = '12') or (CpyCode = '13') or (CpyCode = '14')) and Account not like 'A00090*'"

Open in new window

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 13

Expert Comment

by:John Tsioumpris
ID: 41884234
I'd go this way
Me.Filter = "( CPYCODE BETWEEN 12 AND 14) AND (Account NOT IN ( 'A00090', 'A00091', 'A00092', 'A00093', 'A00094'))"
Me.FilterOn=True

Open in new window

0
 
LVL 30

Accepted Solution

by:
hnasr earned 500 total points
ID: 41884393
Try:
Me.Filter = "CPYCODE like ""1[2-4]"" AND ACCOUNT NOT LIKE ""A0009[1-4]"""
Me.FilterOn = True

Open in new window

0
 

Author Closing Comment

by:Jack Marley
ID: 41886083
Thanks all, I went for hnasr's solution in the end but they all work well.
Cheers.
0
 
LVL 30

Expert Comment

by:hnasr
ID: 41889100
Welcome!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now