How to Cancel a Form Close –Access VBA

How to cancel a form close on the On Unload Event

Sometime we need a program to check if the needed information has been entered. For instance, we need a customer phone number from customer. However, the field is left blank. We want to remind user that the phone number is not entered yet when a form is closed.

need phone

Under the Property Sheet of Form Design, we will need to put the reminder code under the Event Procedure of Form On Unload Event.

unload event

Put the VBA code below under the On Unload Event procedure. My customer phone field is customerPhone.

Private Sub Form_Unload(Cancel As Integer)
Of course he  discount cialis generic respected the dosage. viagra pill  Chromosome 9 has received the most attention. (Treichel 2006). Contraindications: Kamagra Oral Jelly is contraindicated in patients with hypersensitivity to the medicine or the individuals who are over the age of 50. levitra de prescription Criteria for salary and bonuses are also examined, as well as criteria for rating workers for leadership  generic cialis australia advancement. If IsNull(Me.customerPhone) then
   If MsgBox("There is no phone number entered. Do you really want to exit?", vbYesNo, "Exit Confirm") = vbNo Then
       Cancel = True
   End If
End If
End Sub

After the Exit button is clicked, the confirm exit message will pop up when a customer phone field is blank. If user answers No then it will cancel the form close and go back to current form. If user answers Yes then it will close the form. If the customer phone field has a phone number, the message will not pop up on form closes.

message on exit

 

Related posts