Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > Access数据库-模块/函数/VBA

【译文】当用户删除一条记录时,显示一个自定义的对话框

时 间:2013-08-13 09:16:53
作 者:周芳   ID:24526  城市:上海
摘 要:当用户删除一条记录时,显示一个自定义的对话框
正 文:

来自:微软  翻译:周芳

【译文】当用户删除一条记录时,显示一个自定义的对话框


      当你选择了一个窗体中的一条记录并要删除它,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




Access软件网官方交流QQ群 (群号:54525238)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助