MS Access:在计算的字段表达式中处理今天的日期 [英] MS Access : Dealing with today's date in calculated field expression

查看:215
本文介绍了MS Access:在计算的字段表达式中处理今天的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在MS Access中创建一个表格,用于存储学校中儿童的详细信息.

我有一个名为YearGroup的字段,该字段需要根据他们的出生日期以及他们上一年还是下一年来计算他们所在的学年.

即如果表达式认为它们已经六岁了,则应将其放置在第二年.如果将它们向下或向上移动,则应位于第一年或第三年(这是基于表YearModifier中的另一个字段).

我目前的代码是这样:

Year(Now()) - IIf(Month([DOB]) > 8, Year([DOB]) + 6 + [YearModifier], Year([DOB]) + 5 + [YearModifier])

我的问题是Year(Now())作为无效表达式返回.许多网站已经认识到使用Now()函数,并且我也尝试过使用Date(),但是Access似乎没有接受任何东西(版本为2010).

这是怎么回事?如何在计算出的字段表达式中获取今天的日期?

谢谢

解决方案

尝试使用表中的所有字段创建查询,然后添加一个额外的字段YearGroup: Year(Now()) - IIf(Month([DOB]) > 8, Year([DOB]) + 6 + [YearModifier], Year([DOB]) + 5 + [YearModifier])

似乎Date函数不能在表中的计算列中使用.

Hi I am creating a table in MS Access to store the details of children in a school.

I have a field called YearGroup which needs to calculate the school year they are in based on their date of birth and whether they have been moved up or down a year.

I.e. if the expression deems they are six years old they should be placed in year 2. If they were moved down or up a year they should be in year 1 or 3 (this is based on another field in the table called YearModifier).

The code I have at the moment is this:

Year(Now()) - IIf(Month([DOB]) > 8, Year([DOB]) + 6 + [YearModifier], Year([DOB]) + 5 + [YearModifier])

My problem is that Year(Now()) is returning as invalid expression. Lots of websites have recognised using the Now() function and also I've tried Date() but nothing seems to be accepted by Access (The version is 2010).

What is going on? How can I get today's date in a calculated field expression?

Thanks

解决方案

Try creating a query with all of the fields from your table, and then add an extra field YearGroup: Year(Now()) - IIf(Month([DOB]) > 8, Year([DOB]) + 6 + [YearModifier], Year([DOB]) + 5 + [YearModifier])

It appears that Date functions can't be used in calculated columns in tables.

这篇关于MS Access:在计算的字段表达式中处理今天的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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