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 doc forの末尾にあるサンプルに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 に答える