• Clear form and exit (2000)

    • This topic has 4 replies, 3 voices, and was last updated 21 years ago.
    Author
    Topic
    #404905

    I have a subform which has buttons on it to save the entered data or to clear the data and exit the form.
    Save works fine, but a problem with the cancel button.
    Code behind the cancel button is:

    Private Sub CancelAssignment_Click()
    DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
    DoCmd.Close acForm, “NewAssignment”, acSaveNo
    End Sub

    If I have made changes it works correctly, but if I just cancel without having made changes I get the message

    Run-time error ‘2046’:
    The command or action ‘Undo’ isn’t available now.

    What extra code do I need to check if there has been a change before closing the form?

    John

    Viewing 3 reply threads
    Author
    Replies
    • #827149

      [indent]


      What extra code do I need to check if there has been a change before closing the form?


      [/indent]

      The Dirty property of a form does this.

      Wrap your code in

      If Me.Dirty = True Then
      DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
      End If

    • #827150

      [indent]


      What extra code do I need to check if there has been a change before closing the form?


      [/indent]

      The Dirty property of a form does this.

      Wrap your code in

      If Me.Dirty = True Then
      DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
      End If

    • #827184

      You can lose the Access 95 code the wizard builds and make your code clearer by simply using:

      If Me.Dirty Then
      Me.Undo
      End If

    • #827185

      You can lose the Access 95 code the wizard builds and make your code clearer by simply using:

      If Me.Dirty Then
      Me.Undo
      End If

    Viewing 3 reply threads
    Reply To: Clear form and exit (2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: