自动增加 MS Access 2016 表单中的字段 [英] auto-increment a field in MS Access 2016 form

查看:68
本文介绍了自动增加 MS Access 2016 表单中的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个基本表单,并希望表单中的 id 字段在用户打开表单时自动递增(或者也可能是一个不同的事件,只是认为这是最简单的).

I'm building a basic form and would like an id field in the form to auto-increment when the user opens the form (or could be a different event as well, just figured this is simplest).

我已经编写了以下 vb 代码,但似乎存在问题:

I've written the following vb code, but there seems to be an issue:

Private Sub Form_Load()    

    lngNextID = DMax("[portfolio_id]", "table1") + 1
    Form 1.portfolio_id = lngNextID

End Sub

table1 是我希望 vb 查找下一个增量的表.我的表单的名称是Form 1",我希望自动递增的表单中的字段是portfolio_id.

table1 is the table I want the vb to look up for the next increment. The name of my form is 'Form 1' and the field in that form that I'm looking to autoincrement is portfolio_id.

任何建议/修改都会有所帮助,谢谢.

Any advice/modifications would be helpful, thank you.

推荐答案

尝试:

Forms("Form 1").portfolio_id = lngNextID

或者更简单的:

Me!portfolio_id = lngNextID

但是,这将更新打开记录,因此请尝试设置 DefaultValue(字符串):

However, that will update the opening record, so try setting the DefaultValue (a string):

Me!portfolio_id.DefaultValue = "'" & lngNextID "'"

这篇关于自动增加 MS Access 2016 表单中的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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