自定义自动编号 [英] Custom Autonumber
问题描述
我想那次被问到了数百万次,但我没有好运找到
在谷歌上工作的答案。
大多数答案告诉我该做什么,但不知道怎么做。
我的情况是我希望获得以下格式的ID:
< letter> - < three数字>
即
A-001
B-322
字母代表年份A = 2001年,B = 2002年等等,数字每隔一年重新设定。
在谷歌阅读信息之后我决定它会是更简单
有两列,一列用于该字母,第二列用于该号码。
我想出了如何计算字母:
Dim letter As String
letter = Chr $(年(日期) - 2001 + 65)
问题在于数字,我想我应该有单独的表存储
给定年份的最后使用数字,但我真的不知道如何获得/设置
给出V表中的记录B.我查看了访问手册,似乎
有三种不同的方式,示例似乎无法正常工作。
基本上我想拥有带列的表格:
年份[主键],LastNumber
然后,任何人都知道如何从VB:
- 得到给定年份的最后一个数字
- 插入新行
- 更改给定行的值
- 删除给定行
如果有人能帮助我,我会很优雅。
-
ta****@IRCnet.EFne t,ICQ#15827691,TLEN:taked4
* http://eggdrop.takeda.tk - 论坛点。 botównabazie eggdropa *
* http://eggwiki.takeda.tk - pomoc wu?ywaniubotówpopolsku *
I guess that was asked milion times, but I don''t have good luck finding
working answer on google.
Most of the answers tell what to do, but not how.
My situation is that I want to have ID in following format:
<letter>-<three digits>
i.e.
A-001
B-322
letter represents year A=2001, B=2002 and so on, number is resetted every
year.
After reading informations on google I decided that it would be simpler to
have two columns, one for that letter and second for the number.
I figured out how to calculate letter:
Dim letter As String
letter = Chr$(Year(Date) - 2001 + 65)
The problem is with number, I guess I should have separate table to store
last used number for given year, but I don''t really know how to get/set
given record in table in VB. I looked in access manual and there are seem
to be three different ways, and examples doesn''t seem to work.
Basically I want to have table with columns:
Year[primary key], LastNumber
then, anyone know how I can from VB:
- get last number for given year
- insert new row
- change value for given row
- delete given row
If anyone could help me with this I would be graceful.
--
ta****@IRCnet.EFnet, ICQ# 15827691, TLEN: taked4
*http://eggdrop.takeda.tk - forum dot. botów na bazie eggdropa*
*http://eggwiki.takeda.tk - pomoc w u?ywaniu botów po polsku*
推荐答案
(年(日期) - 2001 + 65)
>
问题在于数字,我想我应该有单独的表存储
给定年份的最后使用数字,但我真的不知道如何获取/设置
在VB中的表中给出记录。我查看了访问手册,似乎
有三种不同的方式,示例似乎无法正常工作。
基本上我想拥有带列的表格:
年份[主键],LastNumber
然后,任何人都知道如何从VB:
- 得到给定年份的最后一个数字
- 插入新行
- 更改给定行的值
- 删除给定行
如果有人能帮助我,我会很优雅。
-
ta****@IRCnet.EFne t,ICQ#15827691,TLEN:taked4
* http://eggdrop.takeda.tk - 论坛点。 botównabazie eggdropa *
* http://eggwiki.takeda.tk - pomoc wu?ywaniubotówpopolsku *
(Year(Date) - 2001 + 65)
The problem is with number, I guess I should have separate table to store
last used number for given year, but I don''t really know how to get/set
given record in table in VB. I looked in access manual and there are seem
to be three different ways, and examples doesn''t seem to work.
Basically I want to have table with columns:
Year[primary key], LastNumber
then, anyone know how I can from VB:
- get last number for given year
- insert new row
- change value for given row
- delete given row
If anyone could help me with this I would be graceful.
--
ta****@IRCnet.EFnet, ICQ# 15827691, TLEN: taked4
*http://eggdrop.takeda.tk - forum dot. botów na bazie eggdropa*
*http://eggwiki.takeda.tk - pomoc w u?ywaniu botów po polsku*
Dariusz Kuli?ski / TaKeDa写道:
Dariusz Kuli?ski / TaKeDa wrote:
阅读谷歌信息后我决定
有两个列会更简单,一个用于那个字母,第二个用于数字。
我想出了如何计算字母:
Dim letter As String
letter = Chr
After reading informations on google I decided that it would be simpler to
have two columns, one for that letter and second for the number.
I figured out how to calculate letter:
Dim letter As String
letter = Chr
(年(日期) - 2001 + 65)
您可以使用asc(A)代替65.它的数值是相同的,当然是
,但很明显65这意味着什么。
基本上我想要有列的表:
年[主键],LastNumber
您想要使用最新使用的数字维护一个单独的表吗?
是一种稳定的多用户记录输入方法。好。对于单个用户,
这是不必要的(但无论如何都会工作)。
然后,任何人都知道我可以从VB:
- 获取最后一个号码给定年份
dmax(yourNumberField,yourTable,yourYearField ="& givenYear
- 插入新行
通过执行一个SQL语句(INSERT INTO),通过
currentdb.execute< sql-string>或者使用.AddNew来执行一个RecordSet
对象。
- 更改给定行的值
同样:使用SQL(UPDATE)或使用。编辑和。更新
RecordSet(在你完成.FindFirst之后)
- 删除给定行
(Year(Date) - 2001 + 65)
You could use asc("A") instead of 65. Its numerical value is the same,
of course, but it will be apparent what the 65 means.
Basically I want to have table with columns:
Year[primary key], LastNumber
You want to maintain a separate table with the latest used number? That
is a stable approach to multi user record entry. Good. For single user,
that is not necessary (but will work anyway).
then, anyone know how I can from VB:
- get last number for given year
dmax("yourNumberField","yourTable","yourYearField= " & givenYear)
- insert new row
either by executing a SQL statement (INSERT INTO), which is done via
currentdb.execute <sql-string>, or by using the .AddNew of a RecordSet
object.
- change value for given row
likewise: by using SQL (UPDATE), or using .Edit and .Update of a
RecordSet (after you''ve done .FindFirst)
- delete given row
SQL:DELETE,RecordSet.Delete(在你完成.FindFirst之后)
如果你只是想获得给定年份的第一个可用数字,你可以/>
可以在主表上使用上面的DMax()函数。这是短暂的
,对于单个用户来说,可靠。
-
Bas Cost Budde,荷兰
http://www.heuveltop.nl/BasCB/msac_index.html
我更喜欢人工邮件高于自动化,所以在我的地址中
用茶替换队列
SQL: DELETE, RecordSet.Delete (after you''ve done .FindFirst)
If you just want to get the first available number for a given year, you
could use the DMax() function as above on the main table. That is short
and, for single user, reliable.
--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
I prefer human mail above automated so in my address
replace the queue with a tea
这篇关于自定义自动编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!