我在调试与MS Access表单上的删除按钮关联的一些VBA代码时遇到问题。我在本网站上看到了通过简单调试解决错误3061的其他多个问题。即正确地提出正确引用列的意见,如下文所示:(Too few parameters. Expected <number>. (Error 3061))。
我似乎没有同样的问题。对于某些背景:这是Access窗体上的删除按钮,后端是SQL。
这是VBA代码:
Private Sub cmdDelete_Click()
'delete the current Event record as long as related records permit the operation, otherwise report to the user
Dim strSQL As String
On Error GoTo Error_Handler
If Not IsNothing(Me!Event_ID) Then
strSQL = "DELETE * FROM tbl_Events WHERE "
strSQL = strSQL & GetCriteriaString("Event_ID=", "tbl_Events", "Event_ID", Me.Name, "Event_ID")
'check to make sure user wishes to delete record
If MsgBox("Are you sure you wish to delete this record?", vbYesNo + vbExclamation, "Delete Record?") = vbYes Then
'if an error is thrown, cancel delete - control jumps to Error_Handler
CurrentDb.Execute strSQL, dbFailOnError
DoCmd.Close acForm, Me.Name
End If
End If
Exit_Handler:
Exit Sub
Error_Handler:
Select Case Err.Number
Case 3200 'related records prevent deletion
MsgBox "There are records related to this record that prevent its deletion. Delete related records first.", vbOKOnly, "Related Records: Cannot Delete"
Resume Exit_Handler
Case Else
MsgBox Err.Number & " - " & Err.Description
Resume Exit_Handler
End Select
End Sub