进入VBA如何取消在关闭事件的一种形式接近? [英] access vba How to cancel a form close in Close Event?

查看:847
本文介绍了进入VBA如何取消在关闭事件的一种形式接近?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我敢肯定,这是很简单的,但我不能找到它。在Access窗体的关闭事件,我怎么能取消关闭窗体?我有一个测试计数表中的记录。如果表中有记录,我想询问用户是否要关闭或回去和他们一起工作。所以,我怎么取消关闭事件?

基于Remou的回答

最后code:

 私人小组Form_Unload(取消作为整数)
    CNT = DCOUNT(recid,BulkEntryTemp)

    如果CNT> 0然后
        如果MSGBOX(您有未保存的条目。退出将其删除。您确定要退出吗?,vbYesNo,退出并删除?)= vbNo然后
            取消= TRUE
        结束如果

    结束如果

结束小组
 

解决方案

您可以使用卸载事件:

  GlobalVar ButtonClicked

私人小组Form_Open(取消作为整数)
     ButtonClicked =假
结束小组

私人ClickMe_Click(取消作为整数)
     ButtonClicked = TRUE
结束小组

私人小组Form_Unload(取消作为整数)
     如果不ButtonClicked然后
         取消= TRUE
     如果最终
结束小组
 

<一个href="http://office.microsoft.com/en-us/access-help/order-of-events-for-database-objects-HP005186761.aspx">Order数据库对象的事件

I'm sure this is very simple, but I can't find it. In the close event of an Access Form, how can I cancel closing the form? I have a test that counts the records in a table. If that table has records, I want to ask the user if they want to close or go back and work with them. So how do I cancel the close event?

FINAL Code based on Remou's answer:

Private Sub Form_Unload(Cancel As Integer)
    cnt = DCount("recid", "BulkEntryTemp")

    If cnt > 0 Then
        If MsgBox("You have unsaved entries.  Exiting will delete them.  Are you sure you want to exit?", vbYesNo, "Exit and Delete?") = vbNo Then
            Cancel = True
        End If

    End If

End Sub

解决方案

You can use the Unload event:

GlobalVar ButtonClicked

Private Sub Form_Open(Cancel As Integer)
     ButtonClicked = False
End Sub

Private ClickMe_Click(Cancel As Integer)
     ButtonClicked = True
End Sub

Private Sub Form_Unload(Cancel As Integer)
     If Not ButtonClicked Then
         Cancel = True
     End if
End Sub  

Order of events for database objects

这篇关于进入VBA如何取消在关闭事件的一种形式接近?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆