[AccessD] Form BeforeUpdate

Tony Septav iggy at nanaimo.ark.com
Tue Jun 24 08:08:22 CDT 2008


Hey Charlotte
Thank you.
But I wasn't trying to cancel the close the form per se. It was about 
the BeforeUpdate
I will try to keep this short, maybe I am doing something wrong but....
If I simply have a bound form with 1 field "Product" and a <Close> 
button with
Msgbox 1
DoCmd.Close
And on the BeforeUpdate for the form
Msgbox 2
DoCmd.CancelEvent
And I change the contents of the field. Then click the <Close> button. 
Msgbox 1 fires first (and close) and then MsgBox 2 fires (and 
cancelevent) next and of course the form closes, which is not what you 
want to happen, you want to show the user the validation tests failed 
and return them to the record in the form.
If remove the BeforeUpDate for the form  and put it in the BeforeUpdate 
in the Product field
Msgbox 2
DoCmd.CancelEvent
And I change the contents of the field. Then click the <Close> button. 
Msgbox 2 fires first and the DoCmd.CancelEvent fires and I never get 
the  MsgBox 1 and the close. This is what you would expect, but I didn't 
want to put BeforeUpdates on all my fields in a form, rather one global 
check.
I know this logic, form vs control BeforeUpdate probably is due to the 
difference between a form versus a controls actions.
So by using a subform I was able to run my validations using the subform 
BeforeUpdate and a close button on the main form.


Charlotte Foust wrote:

>I don't believe you can cancel the form's close event.  You have to use
>the Unload event instead if you want to cancel.  However, a lot depends
>on how your close button behaves.  If it just calls close, then a
>CancelEvent is not going to change that.  If it calls Form_Unload and
>the Unload event calls DoCmd.Close, then the CancelEvent should work, I
>think.
>
>Charlotte Foust
>
>-----Original Message-----
>From: accessd-bounces at databaseadvisors.com
>[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Tony Septav
>Sent: Sunday, 22 June 2008 5:38 a.m.
>To: Access Developers discussion and problem solving
>Subject: [AccessD] Form BeforeUpdate
>
>Hey All
>I am trying to use the BeforeUpdate on a bound continuous form. The code
>works and checks the data in the current record for validation and if an
>error is found it pops up a message and fires the docmd.cancelevent (or
>cancel = true).
>Everything works fine, except when I click on the add, delete, or close
>buttons (mine) in the form's footer, then the code works fine and the
>message pops up, but the docmd.cancelevent doesn't fire. Is this a bug,
>or am I missing something.
>--
>AccessD mailing list
>AccessD at databaseadvisors.com
>http://databaseadvisors.com/mailman/listinfo/accessd
>Website: http://www.databaseadvisors.com
>
>  
>




More information about the AccessD mailing list