Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2011
    Posts
    19

    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:
    Code:
    DoCmd.Close acForm, "frmintervention", acSaveNo
    Application.Quit
    End Sub
    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:
    Code:
    DoCmd****nCommand acCmdUndo
    DoEvents
    DoCmd.Close
    Any ideas or an even easier way?

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    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:
    Code:
    If Me.Dirty = True Then
      If MsgBox("Save changes", vbOkCancel, "Save?" ) = vbCancel then  Me.Undo
    End If
    Have a nice day!

  3. #3
    Join Date
    Aug 2011
    Posts
    19

    Exit form and application without saving record

    I wish everything was as easy! Thanks for the help. This works just fine for what I need.

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome !
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •