Refresh, Validation & Error 2001

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MayoM
    New Member
    • Sep 2008
    • 5

    Refresh, Validation & Error 2001

    My form has some simple validation in the Before Update event. If the validation fails the code ends with

    DoCmd.CancelEve nt

    The form also has an Update command button. This simply runs

    Me.Refresh

    When the button is clicked, Me.Refresh triggers the Before Update code. If the validation fails and DoCmd.CancelEve nt is executed, I get Error 2001 "You cancelled the previous operation" on the Me.Refresh statement.

    The solution which I am reluctant to adopt is to repeat the validation code into the code for the Update command button. This means that the validation will be done twice - on the Update command button and Before Update for the form.

    Is there an alternative to Me.Refresh?

    Is there an alternative to DoCmd.CancelEve nt?
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    Replacing

    DoCmd.CancelEve nt

    with

    Cancel = True

    will solve your problem, I think. I should point out, however, that Refresh doesn't actually update (save) a record. It's used in multi-user databases to show User A any changes that have been made to existing records by Users B, C or D.

    Refresh will not show New Records that have been added by other users nor will it "remove" records deleted by other users.

    To save changes to a record, you can use

    If Me.Dirty Then Me.Dirty = True

    DoCmd.RunComman d acCmdSaveRecord

    or

    Me.Requiry

    The last one will also show those New Records and Deleted Records when this has been done by other users. The drawback to Requery is that, without additional code, it will also take you back to the first record in the recordset.

    Welcome to Bytes!

    Linq ;0)>

    Comment

    Working...