473,666 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query has a problem with December??

Ken
I have a form, that when I open it, it shows all items that are due for
inspection in the current month and that is overdue. This is shown in
continuous view and it has a column that shows overdue months.

So if it was November it would show all the assets due in November with
a "0" in the Overdue column. And if there happen to be some October
left they would be shown with a "1" in the overdue column.

This worked perfect all year until I hit December and no results were
shown. After a quick check of the assets, I seen it should show a bunch
of results for December and November.

What I found was if I change my computer date back to November it works
fine, and if I move it January it works fine, but not December.

My query used this criteria on the InspectionDue field to get the
results:

<=CDate(CStr(Da tePart("m",Date ())+1) & "/1")-1

Someone posted this criteria for me to try:

<= CDate(DatePart( "m",Now()+1 ) & "/1")-1

This seemed to work but when I looked closer it still didn't show
December's records, but it did show November's...wh ich was better then
the one I used.
From what I understand about the statement it is taking the current

month, adding a month, going back to the 1st of the month, and
subtracting a day. I think its having a problem with the new year, but
not sure if the fix. The month is almost over and I'm sure all will be
well, but I looking out for next year.

If anyone has some better date functions that would work I would
appreciate it.

Thanks,
Ken

Dec 22 '05 #1
10 1681
"Ken" <km****@elch.or g> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
I have a form, that when I open it, it shows all items that are due for
inspection in the current month and that is overdue. This is shown in
continuous view and it has a column that shows overdue months.

So if it was November it would show all the assets due in November with
a "0" in the Overdue column. And if there happen to be some October
left they would be shown with a "1" in the overdue column.

This worked perfect all year until I hit December and no results were
shown. After a quick check of the assets, I seen it should show a bunch
of results for December and November.

What I found was if I change my computer date back to November it works
fine, and if I move it January it works fine, but not December.

My query used this criteria on the InspectionDue field to get the
results:

<=CDate(CStr(Da tePart("m",Date ())+1) & "/1")-1

Someone posted this criteria for me to try:

<= CDate(DatePart( "m",Now()+1 ) & "/1")-1

This seemed to work but when I looked closer it still didn't show
December's records, but it did show November's...wh ich was better then
the one I used.
From what I understand about the statement it is taking the current

month, adding a month, going back to the 1st of the month, and
subtracting a day. I think its having a problem with the new year, but
not sure if the fix. The month is almost over and I'm sure all will be
well, but I looking out for next year.

If anyone has some better date functions that would work I would
appreciate it.

Thanks,
Ken

The first day of the current month is:
DateSerial(Year (Date),Month(Da te),1)

so to get the first day of the next month we need to add a month:
DateAdd("m",1,D ateSerial(Year( Date),Month(Dat e),1))

All matching dates must be less than the first of next month, so your
criteria is:
<DateAdd("m",1, DateSerial(Year (Date),Month(Da te),1))

I think...
Dec 22 '05 #2
Well, the only difference between using Date() and Now() is that Now()
includes both the current date and time, Date() gives just the current date.
This should make NO difference in the code you've displayed since you're
only using the month.

The problem you're running into is that "DatePart("m",D ate())+1" returns 13
if the month is December. You than concatenate "/1" to it, resulting in
"13/1". Next, you use CDate() to convert this to a date. If the year is
missing, the current year is assumed, so this becomes "13/1/2005". However,
since there aren't 13 months, VBA assumes this to be dd/mm/yyyy format and
converts it to 13 Jan 2005. Next, you subtract 1, which leaves you with 12
Jan 2005.

Now, to do what you're wanting. I will give this a try, but I need to know
what value is in the field that this criteria is for. Is it a full date or
just a month and year, or what? Do you want to handle anything in the month
the same or should it change part way through the month as the due date
passes (i.e. is it not over due until Dec 1, even if it was due 15 Nov)?

Try:
<=DateSerial(Ye ar(Date()), Month(Date()) + 1, 0)

This will return the last day of the current month. In other words, for
December, this will return 31 December of the current year. The 0 at the end
is actually 1 - 1 (subtract 1 day from the first day of the next month).

--
Wayne Morgan
MS Access MVP
"Ken" <km****@elch.or g> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
I have a form, that when I open it, it shows all items that are due for
inspection in the current month and that is overdue. This is shown in
continuous view and it has a column that shows overdue months.

So if it was November it would show all the assets due in November with
a "0" in the Overdue column. And if there happen to be some October
left they would be shown with a "1" in the overdue column.

This worked perfect all year until I hit December and no results were
shown. After a quick check of the assets, I seen it should show a bunch
of results for December and November.

What I found was if I change my computer date back to November it works
fine, and if I move it January it works fine, but not December.

My query used this criteria on the InspectionDue field to get the
results:

<=CDate(CStr(Da tePart("m",Date ())+1) & "/1")-1

Someone posted this criteria for me to try:

<= CDate(DatePart( "m",Now()+1 ) & "/1")-1

This seemed to work but when I looked closer it still didn't show
December's records, but it did show November's...wh ich was better then
the one I used.
From what I understand about the statement it is taking the current

month, adding a month, going back to the 1st of the month, and
subtracting a day. I think its having a problem with the new year, but
not sure if the fix. The month is almost over and I'm sure all will be
well, but I looking out for next year.

If anyone has some better date functions that would work I would
appreciate it.

Thanks,
Ken

Dec 22 '05 #3
Ken
First of all, thanks for the great explanation, I never knew how it
processed this information and now it makes complete sense as to why it
doesn;t work in December.

My overdue column was also based on this same criteria, so it also
explains why it would mess up when the inpsection due was late in the
month. It would show that it was 11 months overdue if it was due
somewhere around the last day of the month.

To answer your question, the field is a date field, using short date
format, mm/dd/yy.

The way it should be handled is if it's December and it's due anytime
in December, it should be current (not overdue). So if the due date was
12/01/05 and the date was today, it should still be good until 01/01/06
then it should say 1 month overdue.

Thanks,
Ken

Dec 22 '05 #4
Your welcome. One thing to be careful of though. You have just a date in
your field, so what I posted should work ok. When there is just a date in
the field, the time is assumed to be midnight (i.e. zero). If the field
should have a date and time, you can't then just check for <= the date,
because you would be checking for <= midnight on that date. In this case,
you would actually check for < the next day instead of <= today.

--
Wayne Morgan
MS Access MVP
"Ken" <km****@elch.or g> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
First of all, thanks for the great explanation, I never knew how it
processed this information and now it makes complete sense as to why it
doesn;t work in December.

My overdue column was also based on this same criteria, so it also
explains why it would mess up when the inpsection due was late in the
month. It would show that it was 11 months overdue if it was due
somewhere around the last day of the month.

To answer your question, the field is a date field, using short date
format, mm/dd/yy.

The way it should be handled is if it's December and it's due anytime
in December, it should be current (not overdue). So if the due date was
12/01/05 and the date was today, it should still be good until 01/01/06
then it should say 1 month overdue.

Thanks,
Ken

Dec 22 '05 #5
Ken
Thanks again for you help. That looks to have fixed part of it, but I
was wondering if you could look at my overdue criteria?

I put this field in my query (it used to have the same criteria and I
used before, minus the <=)
EndofMonth: DateSerial(Year (Date()),Month( Date())+1,0)

Then I have this one-
Ovd: Format(DateDiff ("d",[InspectionDue],[EndofMonth]),"mm")

My overdue column is controlled by this Ovd field, but it is a month
off. Current inspections, like for December, show 1 in the overdue
column instead of a zero. I previously created another field called
Ovd2: Ovd-1 and then it looked good, but that's probably not the
correct method.

Thanks for your help,
Ken

Dec 22 '05 #6
Anthony England wrote:
All matching dates must be less than the first of next month, so your
criteria is:
<DateAdd("m",1, DateSerial(Year (Date),Month(Da te),1))

I think...


8) 8) I couldn't resist this one...

If you're asking for confirmation of what you've written, it's difficult
to tell when it is written in a "code of a sufficiently poor standard".

Tee hee hee.

Just joking, merry christmas to you. 8)
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Dec 22 '05 #7
Anthony England wrote:
The first day of the current month is:
DateSerial(Year (Date),Month(Da te),1)

so to get the first day of the next month we need to add a month:
DateAdd("m",1,D ateSerial(Year( Date),Month(Dat e),1))

All matching dates must be less than the first of next month, so your
criteria is:
<DateAdd("m",1, DateSerial(Year (Date),Month(Da te),1))

I think...


Although what you show is correct, DateSerial should automatically
convert a month 13 into 1 so:

< DateSerial(Year (Date), Month(Date) + 1, 1)

would be a little simpler.

James A. Fortune
CM********@Fort uneJames.com

Dec 22 '05 #8
"Tim Marshall" <TI****@PurpleP andaChasers.Moe rtherium> wrote in message
news:do******** **@coranto.ucs. mun.ca...
Anthony England wrote:
All matching dates must be less than the first of next month, so your
criteria is:
<DateAdd("m",1, DateSerial(Year (Date),Month(Da te),1))

I think...


8) 8) I couldn't resist this one...

If you're asking for confirmation of what you've written, it's difficult
to tell when it is written in a "code of a sufficiently poor standard".

Tee hee hee.

Just joking, merry christmas to you. 8)
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me


Indeed. Not only did no-one want to steal it, but the OP didn't even want
it handed to him for free!
Merry Christmas,
Dec 22 '05 #9

<CD********@For tuneJames.com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
Anthony England wrote:
The first day of the current month is:
DateSerial(Year (Date),Month(Da te),1)

so to get the first day of the next month we need to add a month:
DateAdd("m",1,D ateSerial(Year( Date),Month(Dat e),1))

All matching dates must be less than the first of next month, so your
criteria is:
<DateAdd("m",1, DateSerial(Year (Date),Month(Da te),1))

I think...


Although what you show is correct, DateSerial should automatically
convert a month 13 into 1 so:

< DateSerial(Year (Date), Month(Date) + 1, 1)

would be a little simpler.

James A. Fortune
CM********@Fort uneJames.com


.... should automatically convert a month ... sounds a little less assertive
than it needs to. Without sounding too sure of yourself, I think you could
write ... will automatically convert ...
Merry Christmas
Dec 22 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
7994
by: PMBragg | last post by:
Thank you in advance. I'm trying to pull all inventory items from December of the previous year back to 4 years for my accountant. I know this can be done, but I'm drawing a blank. I've tried; DateDiff("y",-4,DateIn) and get errors Please any assistance would be greatly appreciated. Michael
1
4979
by: PMBragg | last post by:
ORINGINAL Post >Thank you in advance. I'm trying to pull all inventory items from December >of the previous year back to 4 years for my accountant. I know this can be >done, but I'm drawing a blank. I've tried; > >DateDiff("y",-4,DateIn) and get errors > >Please any assistance would be greatly appreciated. >
1
1847
by: Colm O'Brien | last post by:
I have a field called year end month where records hold the month financial year end for accounts is stored. i need to query the data base and return all records where year end month is less than or equal to user input (eg april) any ideas
2
1774
by: Kevin | last post by:
Hi I have the code below that allows me to test the result of a query The query is a crosstab and pivots on months what i want to do is check if the field december is different to blank and if so increment the textbox. the problem is 1. if no value for december the field is not included in the result 2. assuming i can get over 1st problem how can i check if field december is different to space?
3
2367
by: Ken Mylar | last post by:
I have a problem that just showed up and I'm not sure why. I have a query that is supposed to show all records that have an Inspection Due Date any time in the past up until the end of the current month. Somehow I came up with something that worked, and has been fine for the past year. Now all of a sudden when I try to open the form, it doesn't have any records, when I know it should have some.
14
3483
by: Tina | last post by:
My employer tracks productivity/performance of clinicians (how much they bill) each week, its averages for the month, and the 6 months. These averages are compared to their expected productivity. However, the expectation changes - it may be 60% for a while, then change to 50%. Initially, I was averaging the expectation, along with the productivity, but what I'm being asked is to look at the average productivity/performance compared to...
3
1921
by: patrickkellogg | last post by:
I have this code when you click the buttom is suppose to add a job history. it works with firefox, opera, but not ie. (please note - new entries don't have all the elements in them yet, but enough to get the idea). Here is the code: ----------------------------------------------------------------- <html>
22
31188
by: Stan | last post by:
I am working with Access 2003 on a computer running XP. I am new at using Access. I have a Db with a date field stored as mm/dd/yyyy. I need a Query that will prompt for the month, ie. 6 for June, and will return all records in that month.
6
6299
craigfr
by: craigfr | last post by:
I am making a graph comparing last year's defect data with YTD defect data. Our fiscal year starts Nov.1 and ends Oct.31. To get the YTD, I started used a simple date serial criteria: Between DateSerial(Year(Date())-1,11,1) And Date() This works, but only for 10 months out of the year. If your'e in December, it will calculate the YTD from last year's November to the current December, not the last November. My solution was to make an...
0
8443
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8866
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8550
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8639
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6192
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1772
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.