How do I close a form without saving the record

  • Thread starter Thread starter Ayo
  • Start date Start date
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
 
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]
 
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]
 
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
 
Back
Top