473,406 Members | 2,843 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,406 software developers and data experts.

Form Filter Length

72 64KB
Hi was wondering if this filter is ok to be shortened this way:

Month([DateProcessed])=1 AND Year(DateProcessed)=2021 OR Month([DateProcessed])=2 AND Year(DateProcessed)=2021 OR Month([DateProcessed])=3 AND Year(DateProcessed)=2021

changed to

Month([DateProcessed]) IN(1,2,3) AND Year(DateProcessed)=2021


Thanks
Feb 8 '21 #1

✓ answered by cactusdata

You could also use:

Expand|Select|Wrap|Line Numbers
  1. DatePart("q", [DateProcessed])=1 AND Year(DateProcessed)=2021
or, to use an index on the field:

Expand|Select|Wrap|Line Numbers
  1. [DateProcessed] Between DateSerial(2021, 1, 1) And DateSerial(2021, 3, 31)

11 2319
isladogs
456 Expert Mod 256MB
I could just give a one word answer but...
The fact that you've asked the question suggests you understand enough to know what the answer is.
Please don't be offended but the easiest way to find out is just to test this for yourself.
Check whether the second method give the same results as the first and if so you've confirmed the answer
Feb 8 '21 #2
cactusdata
214 Expert 128KB
You could also use:

Expand|Select|Wrap|Line Numbers
  1. DatePart("q", [DateProcessed])=1 AND Year(DateProcessed)=2021
or, to use an index on the field:

Expand|Select|Wrap|Line Numbers
  1. [DateProcessed] Between DateSerial(2021, 1, 1) And DateSerial(2021, 3, 31)
Feb 8 '21 #3
Neruda
72 64KB
Yes doesnt work, was hoping for a minor tweak. Thanks!
Feb 8 '21 #4
isladogs
456 Expert Mod 256MB
All you needed to do was put [] around the field in the Year part. This definitely works

SELECT Table1.ID, Table1.DateProcessed
FROM Table1
WHERE ((Month([DateProcessed]) In (1,2,3) And Year([DateProcessed])=2021));
Feb 8 '21 #5
Neruda
72 64KB
works now, missed that, thank you!!
Feb 8 '21 #6
isladogs
456 Expert Mod 256MB
TBH so did I when I originally replied. Otherwise my one word answer would have been Yes!
I had to test it myself to see why it didn't work as written. Hoisted by my own petard!!
Feb 8 '21 #7
NeoPa
32,556 Expert Mod 16PB
I think you'll find the answer to the original question is a simple Yes.

Testing that may not always be straightforward - particularly as you left out the [] when you call the Year() function, but as you've done it the same way on both sides of the comparison then the answer is a simple Yes. They are equivalent.

PS. For my curiosity - Why would the [] be necessary in this case. generally speaking they are only necessary when :
  1. A reserved word is used as the Field name.
  2. The Field name is at all ambiguous.
  3. The Field name contains white space characters or any other characters that could otherwise confuse SQL into treating the name as finished before the end.
I can't see how any of those scenarios pertain in this case so would expect the reference to work perfectly well, with or without the [].
Feb 8 '21 #8
isladogs
456 Expert Mod 256MB
I agree with points 1 - 3 above and also thought the [] were superfluous until I tried it.
However, without the [] in the Year expression, the query editor put quotes around the field and gave a datatype mismatch error
Feb 8 '21 #9
NeoPa
32,556 Expert Mod 16PB
That's weird. When I tried it in Access 2003 it added [] instead.

I just tested in 2019 with the same results. How do you get quotes added?
Feb 9 '21 #10
isladogs
456 Expert Mod 256MB
When I first tested this I just copied the WHERE clause from post #1 and it added them automatically to the Year expression.
I think I tested in A2010 but it may have been A365.

I've since tried typing out exactly the same expression and Access accepted it as written.
I've also tried just omitting the [] brackets in both expressions - again it worked fine.
Totally confused now....
Feb 9 '21 #11
NeoPa
32,556 Expert Mod 16PB
IslaDogs:
Totally confused now....
You & me both brother! That precisely describes my current understanding.
Feb 9 '21 #12

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

Similar topics

12
by: Pudlik, Szymon | last post by:
Hi, I've written some code: function onSubmit(form){ for (var i = 0; i < form.elements.lenght; i++){ if (form.elements.disabled == 1) form.elements.disabled = 0; }
14
by: Nothing | last post by:
I have a form that has a Tab Control on it. On one of the tab control pages, there are only 3 pages, is a combo box based on a field called departments in a table. When the user selects one of...
0
by: Simon | last post by:
Dear reader, Under Tools>>Options>>Tables/Queries there is a setting possible of "SQL Server Compatible Syntax (ANSI 92)". The two tick boxes here are · "This database" · ...
0
by: EddiePhoenix | last post by:
This is the problem. When running a form filter on a form in acces instead of getting the form back with no data the page is returned filled white. This typically happens when a double filter is...
2
by: Henrootje | last post by:
Hello there! I have a piece of code in a module (function) that constructs a filter. But now I run into a problem..... It seems that I can only set a filter form a module if I open the form...
5
by: phill86 | last post by:
Hi, I have a form that I have applied a filter to by using combo boxes which works fine. Is there a way to apply that filter to the forms underlying query Here is the code that I use to...
2
by: phill86 | last post by:
Hi, I am filtering a report using the form filter with the following code DoCmd.OpenReport "report1", acViewReport, , Me.filter Which works fine untill I filter the form on one of the...
7
by: munkee | last post by:
Hi all, I am using Allen's excellent form filter script to filter the results from a query. I would now like to add some further functionality. How do I go about displaying say the top N costs...
0
by: JpjVB | last post by:
Hi, I've developed a form filter that produces a number of hours budgeted by employee/location/practice group/experience level and date available using some Allen Browne code. I have two command...
3
by: rwalle | last post by:
Hi I have a strange problem in a form filter my set up is as follows there is a form named "InAlarmResumeForm" that has a subform "AlmActiveQrySform" the form has Textboxes with datapicker enabled...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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.