1

我正在尝试做一个简单的事情,也许有人可以帮忙,

我想检查用户输入的值是否已经存在于表中,如果不存在,我希望 Access 强制更改书名。这是我检查是否存在的代码:

Private Sub Item_BeforeUpdate(Cancel As Integer)
  If Volume = DLookup("[Volume]", "[Books]", "[Book_name]='" & [Item] & "'") Then
      x = MsgBox("Book already exist", vbOKOnly)
  End If
End Sub

现在,我应该写什么来强制用户更改书名(不删除文本)

非常感谢!

4

1 回答 1

0

您可以通过将 Cancel 变量设置为 true 来取消更新。Msdn 文档末尾的示例BeforeUpdate也显示了一个示例。

Private Sub Item_BeforeUpdate(Cancel As Integer)
  If Volume = DLookup("[Volume]", "[Books]", "[Book_name]='" & [Item] & "'") Then
      x = MsgBox("Book already exist", vbOKOnly)
      Cancel = True 'do not update give the user another try
  End If
End Sub
于 2013-07-21T08:54:34.297 回答