Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Form Validation - if validation fails when closing form, data is lost

Form Validation - if validation fails when closing form, data is lost

Form Validation - if validation fails when closing form, data is lost

I have validation in the Before_Update event.  Works great except for the unload of a form.  
Scenario -
1) user changes data in a field
2) clicks the X on the form to close the form, triggering the unload event
3) prior to the unload event, the before_update event occurs
4) in this scenario, the user entered invalid data, the before_update event is cancelled (cancel = true) due to the validation
5) for some reason, the form_error event occurs - displaying a message box "You can't save this record at this time - do you want to close and lose your data?" (error 2169).  If you click Yes, the form closes and all information is undone. If you answer No, the form redisplays with the data in it.  This is the path I would like to take without having to deal the MS Access's not so
user-friendly at all.  I tried to intercept to place my own message by setting the RESPONSE property of the form_error event to acDataErrContinue.  The problem is - it takes the path as if you had answered "Yes" to the earlier question.

I would really like the data to stay on the screen giving the user the chance to correct the problem before exiting the screen.

Any insite would be greatly appreciated - this is one of those problems you just sit and spin your wheels on!
Thanks to anyone in advance!

Frustrated in New Jersey!

RE: Form Validation - if validation fails when closing form, data is lost

Use Error trapping to trap the specific error.  Then put a messagebox in the error handling routine to display your message when the error occurs.


On Error GoTo Error_Handling

   If Err = 2169 then
   Msgbox = "Your Message"

RE: Form Validation - if validation fails when closing form, data is lost

Thanks for your quick response.

I did put an error message in, but in order to do so, you must bypass the MS Access message - which, if used, displays a yes/no question - whether to close and lose the data or remain open with the data on the screen (this is the desired path).

Unfortunately, when I set the response to acDataErrContinue (to use my own message), I don't seem to have the opportunity to keep the data on the screen.  It leaves the form error event, then goes to the unload event, which I cancel, knowing there is an error.  But the problem is the screen gets cleared, I lose any data the user has typed in.

So, the user doesn't know what they did wrong, and I'm back to square one.

It's frustrating when Access does not give you control when you need it.


RE: Form Validation - if validation fails when closing form, data is lost

Sorry, Donna - I misunderstood.

Don't use the acDataErrContinue constant.  It isn't necessary to display your message, as by trapping the specific error (2169), you automatically circumvent the Access default response.  So your error routine needs to include some code to tell Access what to do once the user clicks a button in your message box.

For more about setting error traps and error-handling statements, have a read of Chapter 8, "Handling Run-Time Errors," in the "Building Applications with Microsoft Access 97." that is included in the valuepak on the "Office" cd.


Constant         Description
acDataErrContinue Continues without displaying
                        the Delete Confirm dialog box.
                        Setting the Cancel argument to
                        False and the Response argument to
                        acDataErrContinue enables Microsoft
                        Access to delete records without
                        prompting the user.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close