复位计数器ID为1,在MS Access每个新的一年 [英] Reset counter ID to 1 for every new year in MS Access

查看:311
本文介绍了复位计数器ID为1,在MS Access每个新的一年的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表, tblContacts tblTrackJob 。每当一个新的纪录即将在 tblContacts 添加,ID喜欢它的 JobNo 字段分配给的值无论 ID tblTrackJob 已储存。编号样的值,以每年重置为1。

例如...

 姓,名,JobNo,dateEntered
 王富强01 2013年1月1日
 李四02 2013年1月2日
 玛丽·托马斯03 2013年1月3日

 乔·亨利·01 2014年1月1日
 

解决方案

由于我们处理的是Access 2010中,我们可以创建一个之前更改数据宏为[tblContacts表分配[JobNo值:

宏会发现,在从记录表中最大的[JobNo]与相应年([dateEntered]),然后加1,这个值给我们在[JobNo]新记录。如果找到相应年度不存在的记录,则新的记录得到了[JobNo]等于1。

I have two tables , tblContacts and tblTrackJob. Every time a new record is about to be added in tblContacts , id like to assign its JobNo field to the value of whatever ID is in tblTrackJob has stored. Id like the value to reset to 1 every year.

For example...

 first name, last name, JobNo, dateEntered
 bob         smith       01    1/1/2013
 john        doe         02    1/2/2013
 mary        Thomas      03    1/3/2013

 Joe         Henry       01    1/1/2014 

解决方案

Since we're dealing with Access 2010 we can create a Before Change data macro for the [tblContacts] table to assign the [JobNo] value:

The macro will find the largest [JobNo] in the table from records with a corresponding Year([dateEntered]), and then add 1 to that value to give us the [JobNo] for the new record. If no existing records are found for the corresponding year then the new record gets a [JobNo] equal to 1.

这篇关于复位计数器ID为1,在MS Access每个新的一年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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