次のシンプルで簡単なコードがあります。
Private Sub Add_Click()
Dim db As Database, rsAtype As Recordset, Criteria As String
Set db = CurrentDb
Set rsAtype = db.OpenRecordset("Asset_Types", DB_OPEN_DYNASET)
Criteria = "Type='" & NOA & "'"
rsAtype.FindFirst Criteria
'**** Following code is Adding a new type of asset to the Asset_Types Table****
If rsAtype.NoMatch Then
rsAtype.AddNew
rsAtype("Type") = Me!NOA
rsAtype("Description") = Me!Desc
rsAtype.Update
MsgBox "New Asset Added"
rsAtype.Close
db.Close
DoCmd.Close
Else
MsgBox "Asset Type " & Me!NOA & " already exists.", 48, "ERROR!"
Me!NOA.SetFocus
End If
End Sub
ここで、アセット タイプが既に存在するかどうかを検索し、更新する代わりに警告を表示します。If ステートメントを 1 つだけ使用してテーブル内の複数の列を検索する方法はありますか? ネストされた If ステートメントを作成したくありません。