How to cancel a form close in Close Event?

后端 未结 3 501
情歌与酒
情歌与酒 2020-12-20 15:58

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 tab

3条回答
  •  自闭症患者
    2020-12-20 16:32

    Study and try this code, it worked for me. Replace necessary variable names with your chosen names. Paste the code in the form_unload Event of your form. WARNING!!!: After you perform this operation you will find it difficult to access your form in design and layout view

        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
    

提交回复
热议问题