Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Feb 2003
    Location
    Warwick, Warwickshire, England
    Posts
    189
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Clear form and exit (2000)

    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

  2. #2
    4 Star Lounger SteveH's Avatar
    Join Date
    Jan 2001
    Location
    Chelsea, Gtr London, United Kingdom
    Posts
    587
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Clear form and exit (2000)

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

    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
    Steve H
    IT Lecturer/Access Developer
    O2K SR3/O2010; Win7Pro

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Clear form and exit (2000)

    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
    Charlotte

Posting Permissions

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