来自:微软 翻译:周芳
【译文】当用户删除一条记录时,显示一个自定义的对话框
当你选择了一个窗体中的一条记录并要删除它,Access显示一个对话框询问用户是否确认删除记录。如果你需要的话,你可以有两种方式防止此对话框出现。你可以取消BeforeDelConfirm事件,在这种情况下,删除取消了。或者你可以设置响应参数的acDataErrContinue BeforeDelConfirm事件过程,在这种情况下,确认删除。
您可以使用一个BeforeDelConfirm事件过程显示一个自定义对话框来处理用户的响应。下面的例子演示了如何使用一个自定义对话框询问用户是否要取消或继续记录删除。
VBA代码如下:
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
Dim strMessage As String
Dim intResponse As Integer
On Error GoTo ErrorHandler
' Display the custom dialog box.
strMessage = "Would you like to delete the current record?"
intResponse = MsgBox(strMessage, vbYesNo + vbQuestion, _
"Continue delete?")
' Check the response.
If intResponse = vbYes Then
Response = acDataErrContinue
Else
Cancel = True
End If
Exit Sub
ErrorHandler:
MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description
End Sub
原文:How to: Display a Custom Dialog Box When the User Deletes a Record
When you select a record on a form and delete it, Access displays a dialog box asking the user to confirm the deletion of the record. If you want, you can prevent this dialog box from appearing in two ways. You can cancel the BeforeDelConfirm event, in which case the deletion is canceled. or you can set the Response argument of the BeforeDelConfirm event procedure to acDataErrContinue, in which case the deletion is confirmed.
You can use a BeforeDelConfirm event procedure to display a custom dialog box and handle users' responses. The following example demonstrates how to use a custom dialog box to ask users whether they want to cancel or proceed with the record deletion.
VBA
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
Dim strMessage As String
Dim intResponse As Integer
On Error GoTo ErrorHandler
' Display the custom dialog box.
strMessage = "Would you like to delete the current record?"
intResponse = MsgBox(strMessage, vbYesNo + vbQuestion, _
"Continue delete?")
' Check the response.
If intResponse = vbYes Then
Response = acDataErrContinue
Else
Cancel = True
End If
Exit Sub
ErrorHandler:
MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description
End Sub