访问,插入后和缺少的ID [英] Access, After Insert and the missing ID

查看:75
本文介绍了访问,插入后和缺少的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将记录插入表中时,我必须创建一个Access Web数据库并遇到一个令人沮丧的问题.

I'm have to create an access web database and running into a frustrating problem when inserting a record into a table.

我正尝试使用插入后宏来设置问题编号字段,从而:

I'm trying to use the After Insert macro to set a problem number field, thusly:

Edit Record
SetField
Name: [Problem Number]
Value =: [ID] (There is no more logic here but even this simplest case fails)

问题在于ID没有值,因此问题编号最终为空白.

The problem is that ID doesn't have a value so Problem number ends up blank.

此逻辑适用于更新后,这很有意义,因为它在那时具有ID.

This logic works on an After Update which makes sense as it has an ID at that point.

无论如何,我都可以实现这一目标而无需切换到VB代码.

Is there anyway I achieve this without switching to VB code.

推荐答案

一些事情.您不希望使用更新后事件来修改当前记录,因为理论上它会导致更新前事件和更新后事件再次触发.这可能会导致循环循环.

A few things. You do not want to use the after update event to modify the current record since it would in theory cause the before update event and the after update event to fire AGAIN. This potentially would cause a circular loop.

如果您仔细考虑一下,只要将记录全部保存到表中就没什么意义了,那么您可以再次编辑记录!实际上,通过设计发现,上下文中的当前记录仅在更新事件之后才是只读的.因此,在更新后事件中,您无法在上下文中的当前记录上执行编辑记录,并且如果检查错误日志,则会收到只读"错误.

And if you think about this it makes little sense RIGHT after you JUST saved the record all nice to the table then you edit the record again! In fact you find by design that the current record in context is read only in that after update event. So you cannot execute an edit record on the current record in context in the after update event and you get a "read only" error if you check the error log.

在更改前事件中,[id]不可用.但是,您肯定可以在更新后事件中使用[id].

In the before change event, [id] is not available. However, you can most certainly pick up and use the [id] in the after update event.

但是,如果要在另一个表中创建NEW记录,则create record块之外的NEXT行允许您使用

However, if you are going to create a NEW record in another table, then the NEXT line outside of the create record block allows you to pick up the just created record with

[LastCreateRecordIdentity]

因此,记录写发生在创建记录块之外的下一行.

So the record write occurs on the next line outside of the create record block.

例如,下面的代码创建了一条新记录,并非常注意代码的缩进".

For example here is some code that creates a new record and note VERY careful the "indentation" of the code.

如果事实上,如果您单击上面的create record命令,则将突出显示整个代码段.请注意,代码的下一行是如何在蓝色代码块的外面,这就是我们可以使用[LastCreateRecordIdentity]的代码.

If fact if you click on the create record command in the above then the WHOLE create block of code will highlight. Note how the NEXT line of code is OUTSIDE of the blue code block and that is the code where we can use [LastCreateRecordIdentity].

蓝色突出显示的代码是这样的:

The blue highlighted code is thus this:

因此,创建记录外的NEXT行是您可以拾取新ID的时间.在上面的代码中,我实际上将刚刚通过returnVars创建的新ID返回"到了调用例程.

So the NEXT line right outside of the create record is when you can pick up the new id. In the above I actually "return" the new id just created via the returnVars to the calling routine.

这篇关于访问,插入后和缺少的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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