I’ve setup a simple form which allows the user to enter a new record into a table. I’m using the table as a datasource, open the form with the new property in the menu button set and it launches fine. My only problem is that if the data on the form passes the validation criteria when I click a button with the cancel action the record is still saved to the table.
What would be the best way to solve this? I could setup a temporary table and insert the record by running validation on it and inserting to the main table when ok is clicked and discard the record otherwise but I think I might be overcomplicating it. Is there something I’ve overlooked in the original form?
A method I was considering was creating a duplicate of the table I want to create, setting this to be in memory, make it the data source for the form (as it doesn’t have to retain the data) and override the ok button to validate the data and if it passes validation write each field to a buffer for the main table and write it in.
I’m fairly certain this would work I’m just not sure if its neccesary if there is a particular way of handling forms for creating new records that I’ve not thought of.
Never mind. I’ve just set the form up to check the recid of the datasource and if the form closes and ok hasn’t been clicked it finds the record in the table and deletes it. It works so it’ll do.
The actual validation itself isn’t the issue. It’s the fact that as soon as the record being written into the form passes validation a new record is created. I’d prefer that instead the record is only created under the circumstance that the user clicks ok on the form.
I suppose which button is being clicked on the form could be considered a form of validation but since this is a form level concern I prefer to keep the control of this at form level.