How to close a form without saving changes, and without getting error msg?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    How to close a form without saving changes, and without getting error msg?

    I have a form, which I open in dialog mode, and through the openArgs I set some values in the form (in a new record) thus dirtying the form.

    The idea is then that the user should make a selection in a combobox and then just close the form again.

    However, if you close the form without making a selection in the combobox, I do NOT want to save the record since its only half-finished. So I have simple code in the forms BeforeUpdate, to check if combobox is null, and if so, set Cancel=True (cancelling the update)

    However, the user then gets a msgbox saying the record could not be saved, possible due to an error in the database. Now a msg like that is gonna freak out the standard user.

    How do I prevent this error message from happening?

    Other info:
    Access 2003
    Form is opened in dialog, in Add-Only mode.
  • MikeTheBike
    Recognized Expert Contributor
    • Jun 2007
    • 640

    #2
    Hi

    I normaly control sutch things with a 'Close' button event (ie not using the forms control box), but you could try adding Me.Undo at an appropriate point in your code, but not sure if this will cause a probelem in before update event or in a dialogue form without trying it.

    Just a suggestion.

    MTB

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32661

      #3
      Me.Undo should work for you Smiley, but a better way to approach this (avoiding all the related issues) would be to set the .DefaultValue rather than the .Value one. This doesn't dirty the buffer at all, yet assures that your proposed value is used in any new record if it is indeed created.

      Comment

      Working...