自定义的自动编号ID。 [英] Customized autonumber ID.

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

问题描述

我必须创建一个RecordID,它应该是唯一的并且是自动增量的。规格如下:


1)数字必须是9位数

2)前两位应代表当前YY,每年应增加

3)接下来的7位数字应该是0000001,应该是自动增量的(比如连接到当前年份的7位数长的自动编号)


所以最终的数字应该是看起来像这样:090000001,090000002,等等。


我的方法应该是什么?

一如既往地提前感谢!!

I have to create a RecordID which should be unique and autoincremented. The specifications are something like,

1) The number must be 9 digits long
2)First two digits should represent current YY, which should increment every year
3)Next 7 digits should be like 0000001 and should be autoincremented (like 7 digits long autonumber concatenated to the current year)

so the final number should look like this: 090000001, 090000002, and so on.

What should be my approach to this?
Thanks in advance as always!!

推荐答案

如果使用数字字段,则可能无法存储前面的零,因此可能是字符串。这就是我认为你会这样做的方式。


用DMax获取最大RecordID。

将前2个字符转换为整数。 />
看看它们是否等于当前的2位数年份。

如果是这样,

- 将RecordID的其余部分转换为整数。 />
-Add 1(处理溢出?)

- 创建一个字符串,将其设置为等于该数字。

-Append" 0"到字符串的前面,直到它的正确长度为7

- 用年份字符串组合它。

否则,

- 创建一个字符串,其中包含当前年份的前两位数字和0000001

结束if。

完成。
You may not be able to store preceding zeros if you use a number field, so probably a string. Here''s how I think you would do it.

Get the max RecordID with DMax.
Convert the first 2 characters to an integer.
See if they are equal to the current 2 digit year.
If so,
-Convert the rest of the RecordID to an Integer.
-Add 1 (deal with overflow?)
-Create a string, set it equal to the number.
-Append "0" to the front of the string until it is the proper length of 7
-Combine it with the year string.
Else,
-Create a string with the first two digits of the current year and "0000001"
End if.
Done.


你'如果可以的话,最好把它留作Text,但话说回来,这个简单的函数应该可以解决问题。我会让你知道可能的年份变化:
You''re probably better off leaving it as Text if you can, but that being said, this simple Function should do the trick. I''ll leave it up to you to figure in the possible year change:
展开 | 选择 | Wrap | 行号


应放置所有这些编码在Form'的On open_click事件下。我是对的吗?
All these coding should be placed under Form''s On open_click event. Am I right?


这篇关于自定义的自动编号ID。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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