By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,398 Members | 948 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,398 IT Pros & Developers. It's quick & easy.

Refresh, Validation & Error 2001

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

DoCmd.CancelEvent

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.CancelEvent 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.CancelEvent?
Oct 1 '08 #1
Share this Question
Share on Google+
1 Reply


missinglinq
Expert 2.5K+
P: 3,532
Replacing

DoCmd.CancelEvent

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.RunCommand 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)>
Oct 4 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.