访问 - 自定义 "The changes you requested to the table were not succesfull..."

Access - custom "The changes you requested to the table were not succesfull..."

我已将 Duplicates(No) 设置为我的 table 之一。然后我创建了一个带有 Combobox 的表单,用于 select 来自 table 的所有记录,并将 selected 记录存储在加入的 table (ID 外键)字段中。如果我尝试添加具有相同 ID 的另一条记录,Access 会提示我一条警告消息“您对 table 请求的更改未成功...等)。

我想要的是删除这条消息并创建一条自定义消息。这是我尝试过的:

Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim sWhere As String
sWhere = "[ID_Table]=" & Me.Combo5
'
If DCount("*", "Table1", sWhere) > 0 Then 

Cancel = True
Me.Undo
MsgBox " Duplicate"
End If

End Sub

此代码执行 If I select 来自组合框的任何值。这是我的 tables:

Table1
ID_Table(PK)
Field1
Field2 etc.

JoinTable
ID_Join(PK)
ID_Table1(FK)
ID_Table2(FK)

具有 属性 重复项(否)的 ID 字段在表 1 (PK) 中。我怎样才能让它正常工作?

我想通了,多么愚蠢的错误:

而不是

If DCount("*", "Table1", sWhere) > 0 Then 

我不得不改成

 If DCount("*", "JoinTable", sWhere) > 0 Then 

代码无效,因为我引用了错误的 Table。问题已解决,感谢马特的回复。