Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cancel a form close in Close Event?

Tags:

vba

ms-access

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?

like image 980
MAW74656 Avatar asked May 30 '12 14:05

MAW74656


1 Answers

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

like image 88
Fionnuala Avatar answered Nov 15 '22 19:11

Fionnuala