My question here is partly a design problem and partly a error problem.
I use a DLookup in the BeforeUpdate event of a form to verify whether the new entry is a valid primary key- ie, unique.
My own warning box pops up and Cancel is executed if the key is not unique.
This allows the user to return to the form and edit their entry, thus not losing the rest of the data in the form.
This all functions decently.
The problem is this:
When the close button is clicked(I do have custom close buttons and disabled the standard ones for other reasons) and the key is not unique, the msgbox pops up, BUT, when the Ok button is clicked,the form simply exits.
I can live with this but I am sure there must be a way to capture this Close event and have a warning msgbox thrown out.
I am visualising if I could make the above code part of the error handling, there might be a way to detect that 'there is an error raised AND the form is closing, so don't just put the usual warning box up, but put up a 'Ok or Cancel' message box, and either Ok-close form and discard data or Cancel- cancel the onUnload event.
I am thinking of using the raise method, but I can't figure out what the error number should be so I don't conflict with existing errors and possible cause confusion by raising existing errors.
If I catch this XXXX error, I have this blind faith that I might be able to do more with the close event than if I am simple popping a 'Ok' msgbox from ordinary codespace.
I am not sure I am even on the right track with all of this.
Thank you
I use a DLookup in the BeforeUpdate event of a form to verify whether the new entry is a valid primary key- ie, unique.
My own warning box pops up and Cancel is executed if the key is not unique.
This allows the user to return to the form and edit their entry, thus not losing the rest of the data in the form.
This all functions decently.
The problem is this:
When the close button is clicked(I do have custom close buttons and disabled the standard ones for other reasons) and the key is not unique, the msgbox pops up, BUT, when the Ok button is clicked,the form simply exits.
I can live with this but I am sure there must be a way to capture this Close event and have a warning msgbox thrown out.
I am visualising if I could make the above code part of the error handling, there might be a way to detect that 'there is an error raised AND the form is closing, so don't just put the usual warning box up, but put up a 'Ok or Cancel' message box, and either Ok-close form and discard data or Cancel- cancel the onUnload event.
I am thinking of using the raise method, but I can't figure out what the error number should be so I don't conflict with existing errors and possible cause confusion by raising existing errors.
If I catch this XXXX error, I have this blind faith that I might be able to do more with the close event than if I am simple popping a 'Ok' msgbox from ordinary codespace.
I am not sure I am even on the right track with all of this.
Thank you