How do I close a form without saving the record

A

Ayo

I am trying to figure out a way to cancel or close a form without saving the
record. I tried: DoCmd.Close acForm, Me.Name, acSaveNo, but a blank record is
still created.
I want to just be able to close the form without creating anything once I
click cancel. How can I accomplish this? Thanks
 
J

John W. Vinson

I am trying to figure out a way to cancel or close a form without saving the
record. I tried: DoCmd.Close acForm, Me.Name, acSaveNo, but a blank record is
still created.
I want to just be able to close the form without creating anything once I
click cancel. How can I accomplish this? Thanks

acSaveNo refers to saving design changes to the structure of the form, not the
data - often a point of confusion!

You can have your cancel button do

Me.Undo

to restore the contents of the form to what was there when the user started.


John W. Vinson [MVP]
 
A

Ayo

Thank John

John W. Vinson said:
acSaveNo refers to saving design changes to the structure of the form, not the
data - often a point of confusion!

You can have your cancel button do

Me.Undo

to restore the contents of the form to what was there when the user started.


John W. Vinson [MVP]
 
K

Ken Sheridan

To both undo and close the form put code along these lines in the button's
Click event procedure:

Const CANTUNDO = 2046

On Error Resume Next
RunCommand acCmdUndo
Select Case Err.Number
Case 0
' no error
Case CANTUNDO
' anticipated error so do nothing
Case Else
' unanticipated error so inform user
MsgBox Err.Description, vbExclamation, "Error"
Exit Sub
End Select

DoCmd.Close acForm, Me.Name

Ken Sheridan
Stafford, England
 

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