Unanswered: Exit form and application without saving record
I am having a few problems with closing the form and application the user may be using without it saving a record.
The form I have auto fills several fields (e.g. username from the logon screen) of the form and generates a unique Ref Number. Even if the record is not fully filled or a user may wish to close half way through completion, a record is created in the table that is only partially complete.
I have found several answers in forums but all quite complicated.
I have tried:
DoCmd.Close acForm, "frmintervention", acSaveNo
but this still seems to save the record.
I have come across the following but I am not good at VBA to get this to work on my exit button:
The acSaveNo optional parameter prevents the modifications that could have been done to the form itself (its structure) from beeing saved, not the modifications to the data the form presents if it is bound to a data source. Access documentation (Close Method*[Access 2007 Developer Reference]) explains that is parameter is:
A AcCloseSave constant thay specifies whether or not to save changes to the object. The default value is acSavePrompt. With acSaveNo (value: 2) the specified object is not saved.
You could use some code in the forms BeforeUpdate event to check whether data must be saved or not:
If Me.Dirty = True Then
If MsgBox("Save changes", vbOkCancel, "Save?" ) = vbCancel then Me.Undo