自动编码 [英] Autonumber code

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

问题描述

我有一个名为tblseries的表,其中包含字段NextNumber

我还有一个名为form1的表单基于table1在表单上是一个控件

NNum我是'在BeforeUpdate中用以下代码调用NNumtxt

Property = NewNbr()

NewNbr是Module1中的一个函数,该函数的代码是这个


函数NewNbr()作为整数

Dim rst作为DAO.Recordset,db作为DAO.Database

Dim lngNextNumber As Long

设置db = CurrentDb


设置rst = db.OpenRecordset(" tblSeries",dbDenyRead)


rst

..MoveFirst

..编辑

lngNextNumber =![NextNumber]

![NextNumber] = lngNextNumber + 1

..更新

结束

rst.Close

设置db = Nothing

结束功能


我用数字1播种了tblseries但是当我打开我的表格以获得

新记录时没有任何反应j出现了0。


任何人都可以在这里帮忙,为什么这不起作用?我正在使用Access2000

Tony

PS感谢Hugh O''Neill为其他用户发布了原始代码

解决方案

您没有返回从表中检索到的值。就在

结束功能线之前,你需要


NewNbr = lngNextNumber


并假设NextNumber tblSeries中的字段是Long Integer,我会将
的函数声明从Integer更改为Long。


如果你进入tblSeries,你应该看到NextNumber的值是否大于1,这取决于你尝试运行代码的次数是多少次。

-

Doug Steele,Microsoft Access MVP
http://I.Am/DougSteele

" Tony Williams" < tw@tcp.com>在消息中写道

news:bl ********** @sparta.btinternet.com ...

我有一个名为tblseries的表,带有一个字段NextNumber
我还有一个名为form1的表单,基于table1在表单上是一个控件
NNum,我在BeforeUpdate中使用以下代码调用了NNumtxt
Property = NewNbr()
NewNbr是Module1中的一个函数,该函数的代码是这个函数NewNbr()As Integer
Dim rst作为DAO.Recordset,db作为DAO.Database
Dim lngNextNumber As Long
设置db = CurrentDb

设置rst = db.OpenRecordset(" tblSeries",,dbDenyRead)

用rst
。 MoveFirst
。编辑
lngNextNumber =![NextNumber]
![NextNumber] = lngNextNumber + 1
。更新
结束
rst.Close
设置db = Nothing

结束功能

我已经用数字1播种了tblseries但是当我打开
a的表单时,新记录没有任何反应只是一个0出现s。

任何人都可以在这里帮忙,为什么这不起作用?我正在使用Access2000
Tony
PS感谢Hugh O''Neill发布了另一个
用户的原始代码



" Tony Williams" < tw@tcp.com>在消息中写道

news:bl ********** @sparta.btinternet.com ...

我有一个名为tblseries的表,带有一个字段NextNumber
我还有一个名为form1的表单,基于table1在表单上是一个控件
NNum,我在BeforeUpdate中使用以下代码调用了NNumtxt
Property = NewNbr()
NewNbr是Module1中的一个函数,该函数的代码是这个函数NewNbr()As Integer
Dim rst作为DAO.Recordset,db作为DAO.Database
Dim lngNextNumber As Long
设置db = CurrentDb

设置rst = db.OpenRecordset(" tblSeries",,dbDenyRead)

用rst
。 MoveFirst
。编辑
lngNextNumber =![NextNumber]
![NextNumber] = lngNextNumber + 1
。更新
结束
rst.Close
设置db = Nothing

结束功能

我已经用数字1播种了tblseries但是当我打开
a的表单时,新记录没有任何反应只是一个0出现s。

任何人都可以在这里帮忙,为什么这不起作用?我正在使用Access2000
Tony
PS感谢Hugh O''Neill发布了另一个原始代码



用户

Tony

猜测,你试图将某种数字分配给新的
记录 - 大概是因为你发现内置的自动编号没有

完全做你需要的。


首先,你的函数不会返回任何值。例如,将以下行中的

添加到函数末尾:

NewNbr = lngNextNumber


您可能还会考虑何时实际分配新号码。对于

示例,您可以摆脱标准的新记录按钮(

记录选择器上的星号)并将其替换为新按钮在你的表格上

创建一个保存的记录。否则,你可以移动到一个新的记录,更新

表,但后来决定放弃新的记录,让你在系列中缺少
缺少数字。


弗莱彻


您好,我希望我不会介入。我也一直试图在自动编号这个过程中实现

,并使用了来自

Hugh ONeill的原始信息。我也按照以下说明操作,例如NewNbr

= lngNextNumber并将声明更改为Long但仍然没有成功更新我的''原始''表格,这需要

新号码。


我会很感激任何其他建议。

问候

希瑟

" Fletcher Arnold" < FL **** @ home.com>在消息新闻中写道:< bl ********** @ hercules.btinternet.com> ...

" Tony Williams" < tw@tcp.com>在消息中写道
新闻:bl ********** @sparta.btinternet.com ...

我有一个名为tblseries的表,其中包含字段NextNumber
我还有一个名为form1的表单,基于table1在表单上是一个控件
NNum我在BeforeUpdate中使用以下代码调用了NNumtxt
Property = NewNbr()
NewNbr是Module1中的一个函数,该函数的代码是这个函数NewNbr()As Integer
Dim rst作为DAO.Recordset,db作为DAO.Database
Dim lngNextNumber As Long
设置db = CurrentDb

设置rst = db.OpenRecordset(" tblSeries",dbDenyRead)

使用rst
.MoveFirst .Edit
lngNextNumber =![NextNumber]
![NextNumber] = lngNextNumber + 1
。更新
结束
rst.Close
设置db =什么都没有

结束功能

我已经用数字1播种了tblseries但是当我打开我的表单


一个

新记录没有任何事情只会出现0。

任何人都可以在这里帮忙,为什么这不起作用?我正在使用Access2000
Tony
PS感谢Hugh O''Neill发布了另一个


用户的原始代码

嗨Tony
猜测一下,你试图将某种数字分配给新的
记录 - 大概是因为你发现内置的自动编号并不能完全符合你的需要。

首先,您的函数不会返回任何值。例如,将
以下行添加到函数末尾:
NewNbr = lngNextNumber

您可能还会考虑何时实际分配新数字。对于
示例,您可以摆脱标准的新记录按钮(
记录选择器上的星号),并将其替换为表单上的新按钮
创建已保存的记录。否则,您可以移动到新记录,更新表格,但后来决定放弃新记录,留下系列中缺少的数字。

Fletcher



I have a table called tblseries with a field NextNumber
I also have a form called form1 based on table1 On the form is a control
NNum which I''ve called NNumtxt with the following code in the BeforeUpdate
Property =NewNbr()
NewNbr is a function in Module1 the code for the function is this

Function NewNbr() As Integer
Dim rst As DAO.Recordset, db As DAO.Database
Dim lngNextNumber As Long
Set db = CurrentDb

Set rst = db.OpenRecordset("tblSeries", , dbDenyRead)

With rst
..MoveFirst
..Edit
lngNextNumber = ![NextNumber]
![NextNumber] = lngNextNumber + 1
..Update
End With
rst.Close
Set db = Nothing

End Function

I have seeded the tblseries with the number 1 but when I open my form for a
new record nothing happens just a 0 appears.

Can anyone help here, why doesn''t this work? I am using Access2000
Tony
PS With thanks to Hugh O''Neill who posted the original code for another user

解决方案

You''re not returning the value you retrieved from the table. Just before the
End Function line, you need

NewNbr = lngNextNumber

And, assuming that the NextNumber field in tblSeries is a Long Integer, I''d
change the declaration of the function from Integer to Long.

If you go into tblSeries, you should see that the value of NextNumber is
considerably different than 1, depending on how many times you''ve tried
running your code.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
"Tony Williams" <tw@tcp.com> wrote in message
news:bl**********@sparta.btinternet.com...

I have a table called tblseries with a field NextNumber
I also have a form called form1 based on table1 On the form is a control
NNum which I''ve called NNumtxt with the following code in the BeforeUpdate
Property =NewNbr()
NewNbr is a function in Module1 the code for the function is this

Function NewNbr() As Integer
Dim rst As DAO.Recordset, db As DAO.Database
Dim lngNextNumber As Long
Set db = CurrentDb

Set rst = db.OpenRecordset("tblSeries", , dbDenyRead)

With rst
.MoveFirst
.Edit
lngNextNumber = ![NextNumber]
![NextNumber] = lngNextNumber + 1
.Update
End With
rst.Close
Set db = Nothing

End Function

I have seeded the tblseries with the number 1 but when I open my form for a new record nothing happens just a 0 appears.

Can anyone help here, why doesn''t this work? I am using Access2000
Tony
PS With thanks to Hugh O''Neill who posted the original code for another user



"Tony Williams" <tw@tcp.com> wrote in message
news:bl**********@sparta.btinternet.com...

I have a table called tblseries with a field NextNumber
I also have a form called form1 based on table1 On the form is a control
NNum which I''ve called NNumtxt with the following code in the BeforeUpdate
Property =NewNbr()
NewNbr is a function in Module1 the code for the function is this

Function NewNbr() As Integer
Dim rst As DAO.Recordset, db As DAO.Database
Dim lngNextNumber As Long
Set db = CurrentDb

Set rst = db.OpenRecordset("tblSeries", , dbDenyRead)

With rst
.MoveFirst
.Edit
lngNextNumber = ![NextNumber]
![NextNumber] = lngNextNumber + 1
.Update
End With
rst.Close
Set db = Nothing

End Function

I have seeded the tblseries with the number 1 but when I open my form for a new record nothing happens just a 0 appears.

Can anyone help here, why doesn''t this work? I am using Access2000
Tony
PS With thanks to Hugh O''Neill who posted the original code for another


user
Hi Tony
At a guess, you are trying to get some sort of number allocated to a new
record - presumably because you found that the built-in autonumber does not
quite do what you need.

Firstly, your function does not return any value. For example, add the
following line to the end of the function:
NewNbr = lngNextNumber

You might also think about when to actually allocate the new number. For
example you could get rid of the standard ''new record button'' (star on the
record selectors) and replace this with a ''new'' button on your form to
create a saved record. Otherwise, you could move to a new record, update
the table but later decide to abandon the new record leaving you with
missing numbers in the series.

Fletcher


Hello, I hope I am not intruding. I have also been trying to achieve
this process of ''Autonumber'' and have used the original message from
Hugh ONeill. I have also followed instructions below such as NewNbr
= lngNextNumber and changed the declaration to Long but have still
been unsuccessful in updating my ''Original'' form which requires the
new number.

I would be grateful for any other suggestions.
regards
Heather
"Fletcher Arnold" <fl****@home.com> wrote in message news:<bl**********@hercules.btinternet.com>...

"Tony Williams" <tw@tcp.com> wrote in message
news:bl**********@sparta.btinternet.com...

I have a table called tblseries with a field NextNumber
I also have a form called form1 based on table1 On the form is a control
NNum which I''ve called NNumtxt with the following code in the BeforeUpdate
Property =NewNbr()
NewNbr is a function in Module1 the code for the function is this

Function NewNbr() As Integer
Dim rst As DAO.Recordset, db As DAO.Database
Dim lngNextNumber As Long
Set db = CurrentDb

Set rst = db.OpenRecordset("tblSeries", , dbDenyRead)

With rst
.MoveFirst
.Edit
lngNextNumber = ![NextNumber]
![NextNumber] = lngNextNumber + 1
.Update
End With
rst.Close
Set db = Nothing

End Function

I have seeded the tblseries with the number 1 but when I open my form for


a

new record nothing happens just a 0 appears.

Can anyone help here, why doesn''t this work? I am using Access2000
Tony
PS With thanks to Hugh O''Neill who posted the original code for another


user
Hi Tony
At a guess, you are trying to get some sort of number allocated to a new
record - presumably because you found that the built-in autonumber does not
quite do what you need.

Firstly, your function does not return any value. For example, add the
following line to the end of the function:
NewNbr = lngNextNumber

You might also think about when to actually allocate the new number. For
example you could get rid of the standard ''new record button'' (star on the
record selectors) and replace this with a ''new'' button on your form to
create a saved record. Otherwise, you could move to a new record, update
the table but later decide to abandon the new record leaving you with
missing numbers in the series.

Fletcher



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

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