查询有问题吗? [英] Query has a problem with December??

查看:52
本文介绍了查询有问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张表格,当我打开它时,它会显示当前月份检查所需的所有物品,这是逾期的。这显示在

连续视图中,它有一个显示逾期月份的列。


因此,如果是11月,它将显示11月到期的所有资产与

a" 0"在逾期列中。如果碰巧有一些10月份剩下的话,那么他们会被显示为1。在过期的栏目中。


这一直都很完美,直到我到了12月才结果显示没有结果显示为
。在对资产进行快速检查后,我看到它应该在12月和11月显示一堆

的结果。


我发现如果我改变我的电脑可以追溯到十一月它可以工作

罚款,如果我一月份它移动它工作正常,但不是十二月。


我的查询使用了这个标准InspectionDue字段获得

结果:


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


有人发布了这个标准让我尝试:


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


这似乎有效,但当我仔细观察它仍然没有显示

12月的记录,但它确实显示了11月的......比我用过的那个更好。


根据我对该声明的理解,它采用当前的



月,增加一个月,回到th e月1日,和
减去一天。我认为它有新的一年的问题,但

不确定是否修复。这个月差不多结束了,我肯定所有人都会很好,但是我明年要关注。


如果有人有更好的约会能起作用的功能我会赞美它。


谢谢,



解决方案

" Ken" <公里**** @ elch.org>在消息中写道

news:11 ********************** @ g43g2000cwa.googlegr oups.com ...

我有一个表单,当我打开它时,它会显示当前月份检查到期的所有项目,这是逾期的。这显示在
连续视图中,它有一个显示过期月份的列。

因此,如果是11月,它将显示11月到期的所有资产
a" 0"在逾期列中。如果碰巧有一些10月剩下的话,它们会显示为1。在过期的栏目中。

这一年都很完美,直到我到了十二月,并且没有显示任何结果。在对资产进行快速检查后,我看到它应该显示12月和11月的一系列结果。

我发现如果我将计算机日期更改回11月它的工作原理
很好,如果我移动它1月它工作正常,但不是12月。

我的查询在InspectionDue字段上使用此条件来获得
结果:

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

有人发布此标准供我试用:

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

这似乎有效但是当我仔细观察时,它仍然没有显示十二月的记录,但它确实显示了十一月的......这比我使用的那个更好。
< blockquote class =post_quotes>根据我对该声明的理解,它正在采用当前的


月,增加一个月,回到本月1日,并减去一天。我认为它有新的一年的问题,但
不确定是否修复。这个月快要结束了,我肯定一切都会好的,但是我明年要关注。

如果有人有更好的约会功能可以工作我会欣赏它。

谢谢,
Ken



当月的第一天是:

DateSerial (年(日期),月(日期),1)


因此,为了获得下个月的第一天,我们需要添加一个月:

DateAdd(" m",1,DateSerial(Year(Date),Month(Date),1))

所有匹配日期必须小于下个月的第一天,所以你的

标准是:

< DateAdd(" m",1,DateSerial(年(日期),月(日期),1))


我想...


嗯,使用Date()和Now()的唯一区别是Now()

包括当前日期和时间,Date()仅给出当前日期。

这样你所显示的代码就没有区别了'

仅使用月份。


您遇到的问题是DatePart(" m,Date()) + 1"如果月份是12月,则返回13

。你不是连接/ 1到它,导致

13/1。接下来,使用CDate()将其转换为日期。如果年份缺少
,则假设当前年份,因此这将变为13/1/2005。但是,

因为没有13个月,VBA认为这是dd / mm / yyyy格式和

将其转换为2005年1月13日。接下来,你减去1,2005年1月剩下12美元。


现在,做你想做的事。我会尝试一下,但我需要知道

该标准适用于该字段的值。是一个完整的日期还是

只是一个月和一年,或者是什么?你想在月内处理任何事情

相同,还是应该在截止日期之前改变,因为到期日

通过(也就是说它要到12月才到期) 1,即使是11月15日到期)?


尝试:

< = DateSerial(年(日()),月(日() )+ 1,0)


这将返回当月的最后一天。换句话说,对于12月的b $ b,这将返回当年的12月31日。最后的0

实际上是1 - 1(从下个月的第一天减去1天)。


-

Wayne Morgan

MS Access MVP

" Ken" <公里**** @ elch.org>在消息中写道

news:11 ********************** @ g43g2000cwa.googlegr oups.com ...

我有一个表单,当我打开它时,它会显示当前月份检查到期的所有项目,这是逾期的。这显示在
连续视图中,它有一个显示过期月份的列。

因此,如果是11月,它将显示11月到期的所有资产
a" 0"在逾期列中。如果碰巧有一些10月剩下的话,它们会显示为1。在过期的栏目中。

这一年都很完美,直到我到了十二月,并且没有显示任何结果。在对资产进行快速检查后,我看到它应该显示12月和11月的一系列结果。

我发现如果我将计算机日期更改回11月它的工作原理
很好,如果我移动它1月它工作正常,但不是12月。

我的查询在InspectionDue字段上使用此条件来获得
结果:

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

有人发布此标准供我试用:

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

这似乎有效但是当我仔细观察时,它仍然没有显示十二月的记录,但它确实显示了十一月的......这比我使用的那个更好。
< blockquote class =post_quotes>根据我对该声明的理解,它正在采用当前的


月,增加一个月,回到本月1日,并减去一天。我认为它有新的一年的问题,但
不确定是否修复。这个月快要结束了,我肯定一切都会好的,但是我明年要关注。

如果有人有更好的约会功能可以工作我会欣赏它。

谢谢,
Ken



首先,感谢您的精彩解释,我从来不知道如何处理这些信息,现在它完全可以理解为什么它不会在12月份工作。


我的逾期专栏也是基于同样的标准,所以它也是

解释了为什么它会在

月份的晚期到期时陷入困境。如果它是在本月最后一天的某个时间到期的话,它会显示已逾期11个月。


要回答你的问题,该字段是一个日期字段,使用短日期

格式,mm / dd / yy。


应该处理的方式是它是12月还是它12月随时可以获得
,它应该是最新的(不是过期的)。因此,如果到期日是

12/01/05并且日期是今天,它应该仍然是好的,直到01/01/06

然后应该说1个月逾期。


谢谢,




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(DatePart("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...which 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

解决方案

"Ken" <km****@elch.org> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.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(DatePart("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...which 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(Date),1)

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

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

I think...


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",Date())+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(Year(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.org> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.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(DatePart("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...which 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



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


这篇关于查询有问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆