Solved

Access VBA Form - Filter Multiple and/or

Posted on 2016-11-11
7
54 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 49

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 49

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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

810 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