GK in the UK
Registered User.
- Local time
- Today, 22:12
- Joined
- Dec 20, 2017
- Messages
- 274
Scenario:
I have validation in BeforeUpdate which cancels the save.
If I enter invalid data on a form, and try to save the record with DoCmd.RunCommand acCmdSaveRecord, my error trap fires and I pop up a message.
In testing, I'm finding that when I try to close the form with the 'X', I get my custom error message, but Form_Undo is also called.
So I lose ALL the data input on the form when I attempt to close with the 'X'.
If the data is valid, the data is saved when I close with the 'X'.
I wasn't expecting this behaviour. Is this how it is or is it something in my code that's undoing the form ? (If it is I haven't found it yet)
I'm aware that I can disable the 'X' for the form and I may do that, but I want to prevent the closure of a form if the user tries to close Access, preferably, without discarding all the data on the form.
I have validation in BeforeUpdate which cancels the save.
If I enter invalid data on a form, and try to save the record with DoCmd.RunCommand acCmdSaveRecord, my error trap fires and I pop up a message.
In testing, I'm finding that when I try to close the form with the 'X', I get my custom error message, but Form_Undo is also called.
So I lose ALL the data input on the form when I attempt to close with the 'X'.
If the data is valid, the data is saved when I close with the 'X'.
I wasn't expecting this behaviour. Is this how it is or is it something in my code that's undoing the form ? (If it is I haven't found it yet)
I'm aware that I can disable the 'X' for the form and I may do that, but I want to prevent the closure of a form if the user tries to close Access, preferably, without discarding all the data on the form.