472,780 Members | 2,095 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

date Filter on form (3 months, non consecutive)

72 64KB
Hi,
would like to filter a form with a form filter, the form has 12 buttons (12 months) and would like to retrieve records depending on which button is pressed.
This filter example works, it shows records from Jan, Feb, and Apr 2021 but I don't get why it shows them all. Should't it show just one month because I used OR?


Month([DateProcessed])=1 AND Year(DateProcessed)=2021 OR Month([DateProcessed])=2 AND Year(DateProcessed)=2021 OR Month([DateProcessed])=4 AND Year(DateProcessed)=2021
Feb 5 '21 #1

✓ answered by isladogs

Add brackets around each section to clarify what the code is doing

Expand|Select|Wrap|Line Numbers
  1. (Month([DateProcessed])=1 AND Year(DateProcessed)=2021) 
  2. OR (Month([DateProcessed])=2 AND Year(DateProcessed)=2021) 
  3. OR (Month([DateProcessed])=4 AND Year(DateProcessed)=2021)
Now can you see why it will show results for each of the months listed

2 1773
isladogs
436 Expert Mod 256MB
Add brackets around each section to clarify what the code is doing

Expand|Select|Wrap|Line Numbers
  1. (Month([DateProcessed])=1 AND Year(DateProcessed)=2021) 
  2. OR (Month([DateProcessed])=2 AND Year(DateProcessed)=2021) 
  3. OR (Month([DateProcessed])=4 AND Year(DateProcessed)=2021)
Now can you see why it will show results for each of the months listed
Feb 5 '21 #2
NeoPa
32,534 Expert Mod 16PB
Hi Neruda.

I think what you're missing in your appreciation of how the SQL WHERE clause works is that it :
  1. ISN'T - an overall description of the logic of which records to get such as :
    Get me all records WHERE A AND/OR all records WHERE B.
  2. IS - a description of the logic for each record :
    Get me all records WHERE (For each record) A AND/OR B.
In your case, assuming I were to choose months Jan & Apr (Forgetting about Year for now.), then I would choose every record which was Jan AND every record which was Apr, because - at an individual record level - Jan OR Apr evaluated to True.

Does that make the logic clearer?
Feb 6 '21 #3

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

Similar topics

1
by: khalid_uk | last post by:
hi can anyone please show me how to put current date in form (drop down) and it should gives the user an error if the want to choose an invalid dates (holidays and past days) and current month and...
3
by: Nathan Bloomfield | last post by:
I am having difficulty filtering dates for a report. I have written the following code on a popup form which works with regular date fields , however, I am now trying to apply the same concept to...
6
by: Tony Miller | last post by:
All I have an aggregate query using the function Month & Year on a datereceived field ie: TheYear: Year() TheMonth: Month() These are the group by fields to give me a Count on another field by...
1
by: Ronniesss1 | last post by:
I have a table called RescheduleIns and another called Shop Complete Table that are opened together on another form called fAll Shop Orders. On this form, all the Shop Complete Table data is...
7
by: Mpho Pole | last post by:
Hi I have a form that feeds filter parameters to a report. My problem stems from using date parameters to filter.My code is as follows: If IsNull(Me.Date.Value) And IsNull(Me.EndDate.Value) Then ...
1
by: mrityunjay11 | last post by:
i want a date selection form in jsp and that variable should be caught in servlet that is how to catch date varible in my servlet. thanks a lot Regards mrityunjay singh
1
by: tmcjunkin | last post by:
I'm trying to back into this project by defining what the user needs to see when they open a form. I'm between beginner and intermediate with vba, but have been using access for years. When the...
5
by: ahd2008 | last post by:
I have a form that pop up on the sessions form. i use the below code to filter the sessions form by the strat date of the course but it seems it is not giving any result. I get only empty fields ...
3
by: dylankirs | last post by:
Hi. Apologies for any incorrect/off technical lingo. Fairly new to Access and would appreciate any help! I'm trying to create a command button that will filter form records based on an already...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.