我试图创建一个按钮来删除子表单中的某些记录。但是我在查询表达式'KEY_ID =“1'中得到“语法错误(缺少运算符)。
我知道问题是什么:属性是文本,因此值需要用单引号括起来。我只是不知道如何编写 VBA 来实现这一点。
Private Sub cmdDelete_Click()
If Not (Me.subKey.Form.Recordset.EOF And Me.subKey.Form.Recordset.BOF) Then
If MsgBox("Confirm Deletion?", vbYesNo) = vbYes Then
Dim strSql As String
strSql = "DELETE FROM KEYS" & _
" WHERE KEY_ID='" & Me.subKey.Form.Recordset.Fields("KEY_ID")
Debug.Print strSql ' <- prints to Immediate window
CurrentDb.Execute strSql, dbFailOnError
End If
End If