9

我确定这很简单,但我找不到。在访问表单的关闭事件中,如何取消关闭表单?我有一个计算表中记录的测试。如果该表有记录,我想询问用户是否要关闭或返回并使用它们。那么如何取消关闭事件呢?

4

3 回答 3

12

您可以使用 Unload 事件:

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  

数据库对象的事件顺序

于 2012-05-30T15:00:04.780 回答
0

研究并尝试这段代码,它对我有用。用您选择的名称替换必要的变量名称。将代码粘贴到表单的 form_unload 事件中。警告!!!:执行此操作后,您会发现很难在设计和布局视图中访问您的表单

    Private Sub Form_Unload(Cancel As Integer)
        userresponse = MsgBox("Are you sure you want close? All your work wouldn't be saved", vbYesNo, "Database Information")
        Select Case userresponse
        Case 6
            Cancel = False
            'this line opens another form in my own case
            DoCmd.OpenForm "EngMenu"  

        Case 7
            Cancel = True
            'this line keeps my own form open in my own case
            DoCmd.OpenForm "UpdateForm"


        Case Else:

            MsgBox "You are not allowed to perform this operation", vbInformation, "Database Information"
        End Select
    End Subenter code here
于 2013-04-08T11:12:57.933 回答
0

使用“Form_BeforeUpdate(取消为整数)”事件并将取消设置为 True。

请注意,除非您添加一些逻辑以实际允许更新数据库,否则您根本无法关闭。

于 2016-06-16T18:08:21.923 回答