record saves no matter what

Discussion in 'Microsoft Access Forms' started by Dave Cullen, Apr 21, 2006.

  1. Dave Cullen

    Dave Cullen Guest

    I want to allow a user to close a form without saving any changes that
    might have been made. Basically an "Abort" function.

    I put a Close button on the form. The code behind this button defaults
    to

    DoCmd.Close

    I added arguments to this by changing it to

    Call DoCmd.Close(, , acSaveNo)

    It doesn't work. No matter what I do Access updates the record with
    whatever changes are made in the form.

    Help please.
     
    Dave Cullen, Apr 21, 2006
    #1
    1. Advertisements

  2. Dave Cullen

    Wayne Morgan Guest

    The acSaveNo is to not save design changes. It is possible to open a form in
    design view and manipulate it using code. When you close it, you can then
    save or not save those design changes. To not save record edits, you need to
    Undo those edits before closing the form. This can be done by pressing the
    Esc key twice. To do the same thing in code, the command is

    Me.Undo
    DoCmd.Close acForm, Me.Name

    If you don't specify what to close, then the item with the focus will be
    closed. Since you just clicked the button on the form to do this, it will
    probably be the form with the button. However, if you have another form open
    with code in its timer event that may cause it to receive the focus, you may
    have a problem if you don't specify what to close.

    --
    Wayne Morgan
    MS Access MVP


    "Dave Cullen" <> wrote in message
    news:...
    >I want to allow a user to close a form without saving any changes that
    > might have been made. Basically an "Abort" function.
    >
    > I put a Close button on the form. The code behind this button defaults
    > to
    >
    > DoCmd.Close
    >
    > I added arguments to this by changing it to
    >
    > Call DoCmd.Close(, , acSaveNo)
    >
    > It doesn't work. No matter what I do Access updates the record with
    > whatever changes are made in the form.
    >
    > Help please.
     
    Wayne Morgan, Apr 21, 2006
    #2
    1. Advertisements

  3. Dave Cullen

    Guest Guest

    Since the user may or may not want to save the changes, I would recommend a
    message box to give the user the option:

    If Me.Dirty and MsgBox("Save Changes to Current Record", vbQuestion +
    vbYesNo, _
    "Record Has Not Been Updated") = vbYes Then
    Me.Undo
    End If
    DoCmd.Close acForm, Me.Name


    "Wayne Morgan" wrote:

    > The acSaveNo is to not save design changes. It is possible to open a form in
    > design view and manipulate it using code. When you close it, you can then
    > save or not save those design changes. To not save record edits, you need to
    > Undo those edits before closing the form. This can be done by pressing the
    > Esc key twice. To do the same thing in code, the command is
    >
    > Me.Undo
    > DoCmd.Close acForm, Me.Name
    >
    > If you don't specify what to close, then the item with the focus will be
    > closed. Since you just clicked the button on the form to do this, it will
    > probably be the form with the button. However, if you have another form open
    > with code in its timer event that may cause it to receive the focus, you may
    > have a problem if you don't specify what to close.
    >
    > --
    > Wayne Morgan
    > MS Access MVP
    >
    >
    > "Dave Cullen" <> wrote in message
    > news:...
    > >I want to allow a user to close a form without saving any changes that
    > > might have been made. Basically an "Abort" function.
    > >
    > > I put a Close button on the form. The code behind this button defaults
    > > to
    > >
    > > DoCmd.Close
    > >
    > > I added arguments to this by changing it to
    > >
    > > Call DoCmd.Close(, , acSaveNo)
    > >
    > > It doesn't work. No matter what I do Access updates the record with
    > > whatever changes are made in the form.
    > >
    > > Help please.

    >
    >
    >
     
    Guest, Apr 21, 2006
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas Simsion
    Replies:
    4
    Views:
    571
    Kelvin
    Nov 10, 2003
  2. Guest
    Replies:
    0
    Views:
    894
    Guest
    Feb 15, 2005
  3. Trotsky

    Calendar Control always returns 2005 no matter what

    Trotsky, Feb 23, 2005, in forum: Microsoft Access Forms
    Replies:
    1
    Views:
    148
    Rob Parker
    Feb 24, 2005
  4. Kim
    Replies:
    0
    Views:
    335
  5. David Pawloski

    A MATTER OF LIFE AND DEATH

    David Pawloski, Sep 19, 2006, in forum: Microsoft Access Forms
    Replies:
    3
    Views:
    159
    David Cox
    Sep 20, 2006
Loading...

Share This Page