Discussion Locked

Access VBA Close form

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
How do I close a form without saving the record?

6 replies

by peyison

The following code will close the form without saving changes to the current record.

Private Sub cbtClose_Click()
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo
DoCmd.Close
End Sub

Hope this helps.

by it_cowboy

the above is correct, but if the record is not 'dirty' (nothing has been entered in the new record), it will cause a error.

Add the following lines around the code mentioned above...

If Me.Dirty Then
[Enter the above code here]
End If

by it_cowboy

That code should be...

Private Sub cbtClose_Click()
If Me.Dirty Then
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo
End If
DoCmd.Close
End Sub

This discussion is closed to new replies.