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
John W. Vinson - 10 Jan 2008 16:25 GMT
>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]
Ayo - 10 Jan 2008 16:34 GMT
Thank John
> >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
[quoted text clipped - 12 lines]
>
> John W. Vinson [MVP]
Ken Sheridan - 10 Jan 2008 16:35 GMT
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
> 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