record saves no matter what

D

Dave Cullen

I want to allow a user to close a form without saving any changes that
might have been made. Basically an "Abort" function.

I put a Close button on the form. The code behind this button defaults
to

DoCmd.Close

I added arguments to this by changing it to

Call DoCmd.Close(, , acSaveNo)

It doesn't work. No matter what I do Access updates the record with
whatever changes are made in the form.

Help please.
 
W

Wayne Morgan

The acSaveNo is to not save design changes. It is possible to open a form in
design view and manipulate it using code. When you close it, you can then
save or not save those design changes. To not save record edits, you need to
Undo those edits before closing the form. This can be done by pressing the
Esc key twice. To do the same thing in code, the command is

Me.Undo
DoCmd.Close acForm, Me.Name

If you don't specify what to close, then the item with the focus will be
closed. Since you just clicked the button on the form to do this, it will
probably be the form with the button. However, if you have another form open
with code in its timer event that may cause it to receive the focus, you may
have a problem if you don't specify what to close.
 
G

Guest

Since the user may or may not want to save the changes, I would recommend a
message box to give the user the option:

If Me.Dirty and MsgBox("Save Changes to Current Record", vbQuestion +
vbYesNo, _
"Record Has Not Been Updated") = vbYes Then
Me.Undo
End If
DoCmd.Close acForm, Me.Name
 

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