Cancelling Save on Bound Form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello, I have a Customer screen that I want to some validation before
creating a new customer. When entering a new customer, I check it the
customer already exists, I then prompt the user with another screen with the
potential existing customer and the user can stop the creation of a new
customer.

I have the following code in a subroutine on the Customer Screen that closes
the screen without creating a new customer row.

Forms!fCustomers.Undo
DoCmd.close acForm, "fCustomers"

This code work fine when called from the customer screen but when called
from my second window it always creates a new row. Anyone know why this is
and how to force the Customer screen not to do a save while closing?

Thanks
 
What happens if you step through the code one line at a time, do you still
have the problem? If you place the windows side-by-side so that you can see
the form as you step through the code, does the form appear to Undo after
the undo line gets executed?

Just guessing. It may be that the form is closing before it gets undone. Try

Forms!fCustomers.Undo
Do Until Not Forms!fCustomers.Dirty
DoEvents
Loop
DoCmd.close acForm, "fCustomers"

Use Ctrl+Break to get out of this if it never quits, but as soon as the form
is no longer dirty (i.e. nothing left to save) it should exit the loop and
close the form.
 
Thanks,
I get the same results walking though the code. I added you code and it
nevers exits the loop. It appears that because I have left the screen, the
undo does not work anymore for the original screen. Is there any other way
to not get the data to save.

Don
 
Is this form a subform? If so, you can't refer directly to it. You have to
refer to the main form and work your way down the path to the subform.

Example:
Forms!Form1.NameOfSubformControl.Form.Undo
 

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

Back
Top