表格上的字段=下一条记录 [英] Field on Form = next record

查看:83
本文介绍了表格上的字段=下一条记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目编号的表单上有一个字段。我基本上希望它是下一个可用的数字(即06010然后是06011等)。在形式I

创建一个文本框并在控制源下我放:


= [Projects]![ProjectID] = [NextNumber]


这不起作用


我试过:


= [项目]![ProjectID] +1


我输入


=最后([ProjectID])+ 1


和它会告诉我正确的数字,但它从来没有把这个数字给表格给我一个主键不能是null错误因为

ProjectID是我的主键。


我试过这个:


[projectID] =最后([ProjectID])+ 1


它不起作用。


很明显我错过了找到下一条记录的部分然后

将值写入表中 - 关于我如何制作这套装置的想法?

I have a field on a form for project number. I basically want it to be
the next available number (ie 06010 then 06011 etc). In the form I
create a text box and under control source I put:

=[Projects]![ProjectID]=[NextNumber]

This does not work

I tried:

=[Projects]![ProjectID]+1

I put in

=Last([ProjectID])+1

and it will show me the correct number but it never wrtes the number to
the table and gives me a primary key can''t be null error since
ProjectID is my primary key.

I tried this:

[projectID]=Last([ProjectID])+1

it does not work.

Clearly I''m missing the part where it finds the next record and then
writes the value to the table-any ideas how I make that set happen?

推荐答案

Kim Webb写道:
Kim Webb wrote:
我在项目编号的表单上有一个字段。我基本上希望它是下一个可用的数字(即06010然后06011等)。在表单中我创建了一个文本框并在控制源下我放了:

= [Projects]![ProjectID] = [NextNumber]
[snip]显然我是''我错过了找到下一条记录的部分,然后将值写入表格 - 任何想法如何使该集合发生?
I have a field on a form for project number. I basically want it to be
the next available number (ie 06010 then 06011 etc). In the form I
create a text box and under control source I put:

=[Projects]![ProjectID]=[NextNumber] [snip]Clearly I''m missing the part where it finds the next record and then
writes the value to the table-any ideas how I make that set happen?



项目ID文本框上表单必须绑定到表中的

字段。这意味着您无法使用

控制源表达式来计算数字。


相反,您应该使用表单的'BeforeUpdate事件来

通过查找

表中的最大数字来计算数字,并在其中添加一个:

Sub Form_BeforeUpdate(...

Me.ProjectID = Nz(DMax(ProjectID,Projects),0)+1

End Sub


我只是猜测文本框和

中的字段,表格被命名为ProjectID,表格被命名为

项目,所以如果我改变那些猜错了。


-

Marsh

MVP [MS Access]


The project ID text box on the form must be bound to the
field in the table. This means that you can not use a
control source expression to calculate the number.

Instead you should use the form''s BeforeUpdate event to
calculate the number by looking up the largest number in the
table and adding one to that:

Sub Form_BeforeUpdate( . . .
Me.ProjectID = Nz(DMax("ProjectID","Projects"), 0) +1
End Sub

I am just guessing the both the text box and the field in
the table are named ProjectID and the the table is named
Projects, so change those if I guessed wrong.

--
Marsh
MVP [MS Access]

确定如此,我已经添加了您建议的[事件程序]和

控制源现在可以提供:


ProjectID

这个领域的



但它只显示空白 - 它没有显示下一个项目t号。

OK so on the form I''ve added the [event procedure] you suggected and
the control source now proint to:

ProjectID

for that field

but it just shows up blank-it does not show me the next project number.


Kim Webb写道:
Kim Webb wrote:
好的,我已经添加了[事件程序]你建议和控制源现在提示:

ProjectID

用于该领域

但它只是显示空白 - 它没有显示下一个项目编号。
OK so on the form I''ve added the [event procedure] you suggected and
the control source now proint to:

ProjectID

for that field

but it just shows up blank-it does not show me the next project number.



在记录为

即将保存之前,BeforeUpdate事件不会触发,所以在

保存之后你才会看到它。您是否导航到另一条记录并返回到新创建的记录(或检查表格)以查看

记录是否以正确的值保存?


-

Marsh

MVP [MS Access]


The BeforeUpdate event doesn''t fire until the record is
about to be saved, so you will not see it until after the
save. Did you navigate to a different record and back to
the newly created record (or check the table) to see if the
record was saved with the correct value?

--
Marsh
MVP [MS Access]


这篇关于表格上的字段=下一条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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