Solved

Access VBA Form - Filter Multiple and/or

Posted on 2016-11-11
7
88 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 51

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 (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 51

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

691 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