Close form without saving record (1 Viewer)

WineSnob

Not Bright but TENACIOUS
Local time
Yesterday, 21:00
Joined
Aug 9, 2010
Messages
211
I have a form I would like to close without saving the record using a button. here is the code I have but it closes the form and it also writes the record to the table.
Code:
Private Sub ClosewoSave_Click()
Cancel = True
Me.Undo
DoCmd.close
DoCmd.OpenForm "frmMenu"
End Sub
I found in a thread that Cancel = True would not write the record.
What am I missing?
Thanks.
 

marlan

Registered User.
Local time
Today, 04:00
Joined
Jan 19, 2010
Messages
409
I found in a thread that Cancel = True would not write the record.
What am I missing?
Thanks.

Hi,

Have you found this in Forms, or in controls?
where is Cancel defined?

I think if you want to not save a record, you shouldn't use a bound form, rather write logic inserting or updating the DB. But then, why do it in Access...

An other way could be Deleting the current record, if you want to not save the data, or have each control on the form's BeforUpdate event save it's oldValue to a local variable, and roll them back if click this close button.

bottom line, in my opinion: bound forms are a graphic display of the actual field. updating data is automatic. Lets keep it that way.

any other opinions?
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 11:00
Joined
Jan 20, 2009
Messages
12,852
I think if you want to not save a record, you shouldn't use a bound form, rather write logic inserting or updating the DB

any other opinions?

A bound form manages conflicts when one user writes to a record that is open by another user. This conflict very complex to manage this without a bound form and data can be lost unless it is done right.

A transacted bound form can even manage multiple records and commit or abandon them at the whim of the user. It is discussed here.

I posted a simple example here in post 9.
 

Fuse3k

Registered User.
Local time
Yesterday, 21:00
Joined
Oct 24, 2007
Messages
74
Code:
Public Sub Button1_Click()
     If Me.Dirty = True Then
          MsgBox "The Form will be closed without saving", vbOkOnly
          DoCmd.Undo
          DoCmd.Close acForm, Me.Name
     End If

End Sub
 

Users who are viewing this thread

Top Bottom