问题描述
我有一个数据输入表单,每次打开表单时都会打开默认值。要求是用户可以编辑表单中的现有数据。当表单关闭时,它不应更新现有记录,而是插入新记录。
在Form-Beforeupdate函数中,我首先检查记录是否已存在(主键存在)。然后我写了一个插入到从表单中选取所有值并插入后端表的SQL。
当我打开表单并输入新的主键值时,我不断收到错误说我正在尝试插入重复记录。有趣的是,它在表格中插入新记录。
我的逻辑如下:
Hi,
I have a data entry form which opens default values each time the form is open. Requirement is that users can edit existing data in the form. When the form is closed, it shouldnt update the existing record but rather insert a new record.
On the Form-Beforeupdate function, I first check if the record already exists (Primary keys exist). Then I wrote a "Insert into" SQL that picks all values from the form and inserts into the backend table.
When I open the form and enter new Primary key values, I keep getting an error saying I''m trying to insert duplicate records. Funny part is, it inserts the new record in the table.
The logic I have is below:
推荐答案
---------------------------------- -------------------------------------------------- ---------------
我认为我在上一篇文章中的逻辑不正确。如果DCOUNT是> 0,它不应该插入一行。
除此之外,我不能在这里使用DCOUNT,因为我的主键是复合键,因此每个键的DCOUNT绝对可以是> 0,但复合键数必须为= 0才能插入新行。
我觉得问题首先是因为我试图插入一行当我关闭表单时,Access form_onClose默认事件也试图插入此行,从而产生冲突。我可以覆盖Form_Close事件以不插入或更新我的记录吗?
这篇关于“插入”创造问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!