View Full Version : Solved: On Close Event
Mattster2020
07-02-2009, 05:21 AM
Afternoon All,
I would just like to know if there is a piece of code / article on how to interupt the 'On Close' event. Fore instance if validation on a particular textbox failed how would you stop the form from closing and remain open?
Regards,
Matt
Matt, Access?
Try the "Unload Event" instead
me.fieldname.setfocus
msgbox me.fieldname & " is not correct"
me.cancel = true
Where fieldname is the actual name of the field being validated.
Mattster2020
07-02-2009, 06:21 AM
Thanks OBP,
I am using Access 2000.
My code as per below:
If Me.[Monday Lunch Out] <= 0 Then
MsgBox ("Please Enter A Lunch Start Time"), vbDefaultButton1, ("Alert")
Me.Monday_Lunch_Out.SetFocus
Me.Cancel
The code executes up to the last line:
Me.Cancel
Error message: Method or Data member not found, im guessing that this may not be compatable with 2000?
Mattster2020
07-02-2009, 07:27 AM
Afternoon,
I have solved the above error with the following code:
Private Sub Form_Unload(Cancel As Integer)
If Me.[Monday Lunch Out] <= 0 Then
DoCmd.CancelEvent
MsgBox ("Please Enter A Lunch Start Time"), vbDefaultButton1, ("Alert")
Me.Monday_Lunch_Out.SetFocus
End If
End Sub
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.