How to interrupt a form close?

L

LAS

I have some validation code in the before_update and before_insert events of
my form. If the form is not valid, cancel = true. It works fine except
when the user clicks the Close event. They get the invalid message, but the
form continues to close. They lose the opportunity to correct their errors
before losing all their other data. Can I stop the close from completing?
This is the code in the Close button.

DoCmd.Close acForm, Me.Name
 
M

Mike

I have some validation code in the before_update and before_insert eventsof
my form.  If the form is not valid, cancel = true.  It works fine except
when the user clicks the Close event.  They get the invalid message, but the
form continues to close.  They lose the opportunity to correct their errors
before losing all their other data.  Can I stop the close from completing?
This is the code in the Close button.

    DoCmd.Close acForm, Me.Name

Did you try using the Form Unload event (and setting Cancel = True) ?
 
L

LAS

Nope. Sounds like it would work for the Close, but now I find that I'm in
trouble when I trigger the Update or Insert events by a .MoveNext. When the
Update or insert is canceled because of bad data, the .MoveNext fails
because of no current record. What is the solution to that flavor of the
problem?

tia (again)
las

I have some validation code in the before_update and before_insert events
of
my form. If the form is not valid, cancel = true. It works fine except
when the user clicks the Close event. They get the invalid message, but
the
form continues to close. They lose the opportunity to correct their errors
before losing all their other data. Can I stop the close from completing?
This is the code in the Close button.

DoCmd.Close acForm, Me.Name

Did you try using the Form Unload event (and setting Cancel = True) ?
 
L

LAS

I finally removed the call to the validation routine from the before_uipdate
and before_insert events and put them wherever I triggered a .movenext or
..addnew or close.... perhaps other places too.
 
D

David W. Fenton

Sounds like it would work for the Close, but now I find that I'm
in trouble when I trigger the Update or Insert events by a
.MoveNext. When the Update or insert is canceled because of bad
data, the .MoveNext fails because of no current record. What is
the solution to that flavor of the problem?

Why are you using .MoveNext? And what are you using it on?

Again, don't use recordsets -- use the form to edit your data.
 
D

David W. Fenton

I finally removed the call to the validation routine from the
before_uipdate and before_insert events and put them wherever I
triggered a .movenext or .addnew or close.... perhaps other
places too.

What kind of validation events are these? Are they for groups of
fields? If so, maybe your data is not structure properly. In
general, for individual fields, validation should occur in the
events of the control used to edit the field, no sooner and no
later. For multi-field validation, I usually suggest a wizard-type
approach, where the task is broken down into steps that limit the
choices for each step, rather than having the user enter a whole
bunch of data and then have it all evaluated at once (like on
annoying web-based forms that don't tell you you've left out fields
until you submit them -- that's a near necessity in web apps, but
something that should be avoided in an Access app).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top