Cancel validation rule message boxes on closing form (1 Viewer)

Fiona H

Registered User.
Local time
Today, 14:49
Joined
Oct 25, 2006
Messages
28
I want to close a form and I am using

Private Sub Form_Close()
Application.Quit
End Sub

as the form opens with the access application window hidden, and I found that the .ldb file didn't close if I simply used the X.

I have a series of fields with validation rules which activate on exit. One of these validation rules is in the box which gets focus when the form opens. This means that I get the validation text error message boxes when I close the form with the X.

If I have started to complete the form, I get a whole host of error messages and validation messages when I try to shut it with the X.

Is there a way of closing the form and cancelling or ignoring all error message boxes. I want the user to be able to close the form if they have decided not to fill it in after all, or have got part way through and want to cancel.

I would really appreciate any help, I am sure this is a very basic question and I should probably be able to find the answer, but I can't and I am very fed up!
 

apr pillai

AWF VIP
Local time
Tomorrow, 03:19
Joined
Jan 20, 2005
Messages
735
Validation Rule

Let us look into it this way: The Form is opened and the Focus is on the First Field but you have entered nothing into it. When you try to close the form by clicking the X Button the OnLostFocus Event takes place in the First Field and the validation Rule triggers the Error Message. To correct this problem at this stage in your validation rule you can check whether the field value is Null if so give a nice exit without triggering the error routine.

If some value partialy entered into one or more field(s) the User can use the Undo Shortcut Ctrl+Z repeatedly (if they are made aware of this corrective action) to unwind what partialy entered and make it totaly a blank new record and close the form.

You can implement the Null checking exercise in all cases as part of the Validation procedure.

To shutdown the Application I use DoCmd.Quit method.
 

Fiona H

Registered User.
Local time
Today, 14:49
Joined
Oct 25, 2006
Messages
28
Thank you so much for replying.

I have worked around the problem by removing all the "required" fields from the table (and then writing some code to force the user to enter data in the relevant box), disabling the X and then making my own close button which runs a macro which closes the form and quits the application.

It has taken me hours, but I am so happy I made access do what I wanted I may now have to do a small celebratory dance!

Thanks again for looking at my post!
 

Users who are viewing this thread

Top Bottom