我有以下简单易行的代码:
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 语句来搜索表中的多个列,我不想创建嵌套的 If 语句。