?
Solved

Access VBA Form - Filter Multiple and/or

Posted on 2016-11-11
7
Medium Priority
?
116 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 52

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 48

Expert Comment

by:Dale Fye
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 52

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: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 17

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 2000 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

How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

777 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