更新时间:2023-11-23 21:46:28
您能否了解更多关于您拥有哪种类型范围的详细信息? 通常Range指的是一个excel对象,这是一个Access论坛。 我也不知道你的日期是字符串还是数字。 Microsoft Office将日期存储为数字,但您的日期
也可以是字符串。 日期编号从1900年1月1日开始,为1 每天也相等1. 所以2011年2月10日是40,585。
所以你的代码看起来像这样。 您必须考虑一个日期是在十二月,第二个日期是在下一年的一月。
OldDay =" 1/1/2011" '作为字符串的日期
NewDay =" 3/1/2011" '作为字符串的日期
OldMonth = month(DateValue(OldDay))
OldYear = year(DateValue(OldDay))
NewMonth = month(DateValue(NewDay))
NewYear = year(DateValue(NewDay))
SkipMonth = False
如果OldYear<> NewYear然后
如果NewYear = OldYear + 1则
如果NewMonth<> 1或OldMonth<> 12然后
SkipMonth = True
结束如果
否则
SkipMonth = True
结束如果
结束如果
如果两个日期是一个月,则SkipMonth将为false aprat群组。如果两个日期相隔一个月,则SkipMonth将为真。
I need function to check for missing months in a range formatted month/year field. ms access 2003
Can yo ugive more details on what type of range you have? Usually Range refers to an excel object and this is an Access forum. I also don't know if your Date is a string or a number. Microsoft office stores dates as a number but your date can also be a string. A date number starts at Jan 1, 1900 as a 1. Each day is also equal 1. So Feb 10, 2011 is 40,585.
So your code would look something like this. You have to consider when one date is in December and the second date is in january of the following year.
OldDay = "1/1/2011" 'a Date as a string
NewDay = "3/1/2011" 'a date as a string
OldMonth = month(DateValue(OldDay))
OldYear = year(DateValue(OldDay))
NewMonth = month(DateValue(NewDay))
NewYear = year(DateValue(NewDay))
SkipMonth = False
if OldYear <> NewYear then
If NewYear = OldYear + 1 then
If NewMonth <> 1 or OldMonth <> 12 then
SkipMonth = True
end if
else
SkipMonth = True
end if
end if
SkipMonth will be false if the two dates are one month aprat. SkipMonth will be true if the two dates are not one month apart.