473,397 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

using applyfilter command to filter 2 criteria in tha same field

25
hi,

i have a form name stock
i need to filter the data with this criteria :
1. status like : "yes"
2. class like : "all"
3. class like : "M2D"

i used this command but not work
Expand|Select|Wrap|Line Numbers
  1.     kr = Me.cmbstatus.Value
  2.     class1 = "all"
  3.     class2 = "M2D"
  4.  
  5.     DoCmd.ApplyFilter , "status like '" & kr & "' and class like '" & class1  & "'and class like '" & class2 & "'"
  6.  
  7.    Me.Refresh
it not work.
how do i have to filter it.

Thank you.
Feb 13 '09 #1
4 6567
Stewart Ross
2,545 Expert Mod 2GB
Hi. Assuming that in all cases Status has to be 'Yes', you need to OR the Class criteria, not AND them. However, you don't seem to be clear about what you are comparing, as you are using Like without using any wildcard characters for matching what goes before and after the string.

There is no need to use Like if you are after an exact match; the = operator is the right one for this. If you need partial matching you will need to use wildcard characters before and after the pattern, as shown below.

I have also used parenthesis for the OR part to ensure that the meaning of the statement and its execution sequence is clear. The AND is being done on the result of the OR, and the parenthesis just ensure that there is no doubt of the order in which they are interpreted.

Equals operator version
Expand|Select|Wrap|Line Numbers
  1. DoCmd.ApplyFilter , "status = '" & kr & "' AND (class = '" & class1  & "' OR class = '" & class2 & "')"
Partial match version
Expand|Select|Wrap|Line Numbers
  1. DoCmd.ApplyFilter , "status Like '*" & kr & "*' AND (class Like '*" & class1  & "*' OR class Like '*" & class2 & "*')"
-Stewart
Feb 13 '09 #2
MikeTheBike
639 Expert 512MB
Hi

As you have not used any wild card characters I assume you shouldn't be using Like in the filter, ie. the strings 'yes', 'all' and 'MDS' are the complete field entries.

If so, then I suggerst something like this:-

DoCmd.ApplyFilter , "status = '" & kr & "' AND (class = '" & class1 & "' OR class = '" & class2 & "')"

Note the bracket and to OR

HTH


MTB
Feb 13 '09 #3
NeoPa
32,556 Expert Mod 16PB
Another way of checking multiple values against a single field is to use the In() function.
Expand|Select|Wrap|Line Numbers
  1. Call DoCmd.ApplyFilter(, "[status]='" & _
  2.                          Me.cmbstatus & _
  3.                          "' AND [class] In('all','M2D')")
  4. Me.Refresh
Feb 13 '09 #4
dbdb
25
well thank you guys,,,
it work...

thanks for your help.
Feb 16 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: CSDunn | last post by:
Hello, I have a problem with field filtering between an Access 2000 Project form (the application is called CELDT), and the report that shows the results of the filter. Both the form and the...
1
by: Michelle Dennard | last post by:
I am attempting to use the ApplyFilter command on a form in access and I am having some questions. Basically I have a form inwhich I select three things that constitute a key for each item. 1)...
4
by: Bob Darlington | last post by:
Can anyone tell me why: DoCmd.ApplyFilter, "ElectID = " & vNewElectID should work in an mdb, but fail when the file is converted to an mde. It fails with a 'Enter Parameter Value: ElectID"...
1
by: S. van Beek | last post by:
Dear reader, How can I filter a numeric field with Like as criteria in a query. To filter a numeric field with <10 as criteria this will com back with the result of those records for which...
5
by: Ron S | last post by:
After days of searching I finally an example that would work with my application, the only problem is after entering all of the code it is not working. Would someone be kind enough to take a look at...
23
by: Steven TK | last post by:
Hi everyone, I wonder who can help me on the filter the Start Date and End Date. I still cannot manage to filter it. Eg. When the user click the StartDate(comboBox as 16/7/07), the Start...
15
by: Briansmi1116 | last post by:
I created two buttons, that filter my form, They filter in different Fields, and if one is filtered, and the other is not there is a certain amount of record, if they are both pushed, then there is...
2
by: dkohel | last post by:
What is wrong with the following code? I am trying to filter a form based on the selection of a combobox named cblPRD Dim currentFilter currentFilter = " = '" & Me!cboPRD & "'" Filter =...
5
Jerry911
by: Jerry911 | last post by:
Hi, I have a query that I use to export data to a spreadsheet. The query itself works fine and I can manually edit the query to supply filtered information. What I would like to do is use a form...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.