【译文】当用户删除一条记录时,显示一个自定义的对话框-周芳
Access软件网QQ交流学习群(群号码198465573),欢迎您的加入!
首页 >技术文章> Access数据库-模块/函数/VBA


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

发表时间:2013/8/13 9:16:53 评论(0) 浏览(7176)  评论 | 加入收藏 | 复制
   
摘 要:当用户删除一条记录时,显示一个自定义的对话框
正 文:

来自:微软  翻译:周芳

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


      当你选择了一个窗体中的一条记录并要删除它,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群(群号:198465573)
 
 相关文章
【译文】5个技巧让你的Access软件提速   【周芳  2013/4/23】
【译文】自动刷新链接 Microsoft Access 表  【周芳  2013/5/7】
【译文】如何取消事件  【周芳(转)  2013/5/21】
【译文】把DAO代码转化为ADO  【周芳(转)  2013/6/4】
【译文】如何防止在窗体上移动时意外清除数据  【周芳  2013/7/30】
常见问答
技术分类
相关资源
文章搜索
关于作者

周芳

文章分类

文章存档

友情链接