Full Version: Which form event for validation?
UtterAccess Forums > Microsoft® Access > Access Forms
Hi folks
I have a form which includes 3 subforms. There are some rules which dictate how many records there should be on the subforms, so I have created some functions which do the validation. The problem is I'm really stuck on which event and on which form this validation should fire from. For example, as far as I can see I can't do the validation from the beforeupdate event of the main form because that fires when the user moves to one of the subforms and of course it won't pass validation as the user hasn't had an opportunity to create the subform records yet.
Basically, when the user has created their complete set of records I want all the records validated, and if passed the save should go ahead, but if any of the forms is in an invalid state in terms of expected number and type of records, the user should get a message and the save should be cancelled, allowing them to correct the records.
I'd really appreciate some advice on which form(s)/event(s) this validation should be called from.
Doug Steele
I don't think what you want is possible.
Is you've alread noted, when you move from the main form to the subform, the main form's BeforeUpdate event fires. Similarly, if you move from a subform to the main form, or from a subform to another subform, the BeforeUpdate event of the form being used as a subform will fire.
Since all you can do in the BeforeUpdate event is accept the changes or reject them, that really means that there's no way to wait until you've completed the editting on all the forms before validating.
Personally, I would do this on a button click. Don't let the user navigate to another record until the validation is complete.
I had to do something similar to what you need once. The solution that worked for me was to unbind the forms so I can validate the data then send the data to the database when the user clicks the "save & close" button. When I did this a few years ago, I didn't know how to use class objects. Were I to do this again, I would create a class object, shift all the data into it, and have methods inside of it that not only validated your data, but also saved it to your tables.
The disadvantage of this solution is you have to manually code populating all your fields, then scraping that data at the end to validate and save it.
- Sligo
Thanks people.
had already started running the validation from buttons, but as I progressed through the labyrinth of validations I began to wonder if there was a simpler way of letting Access lend a hand. Seems not - back to the coding...
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.