How to Solve Update or Cancel Update Without Addnew or Edit Error

D

doyle60

I get an error when I hit a LookUp combo box (to navigate around the
form). It occurs on some new code I wrote in the BeforeUpdate event:

If IsNull(Me.DateSentOrigtxt) Then
Me.DateSentOrigtxt = Me.DateSentLast
End If

The error is this: Run-time Error '3020': Update or Canel update
without AddNew or Edit.

The Help says "On a Microsoft Jet database, you called the Update or
CancelUpdate method but didn't use the AddNew or Edit method before
writing data to a record."

I don't understand this.

The error does not occur if you go to the subform before hitting the
LookUp combo.

The code updates a field with data, as you can probably tell.

How do I get rid of this error?

Thanks,

Matt
 
A

Allen Browne

Yes, this is a somewhat misleading error message. It just means that your
attempt to set the value did not work.

Presumably you have this code in the BeforeUpdate event of DateSentOrigtxt.
Instead of trying to alter the value in the BeforeUpdate event, use the
AfterUpdate event. Either that, or just Undo the control in its
BeforeUpdate.

The same error message occurs in other contexts where Access just means, "Ya
can't do that!" For example, you can get the error if you try to move to
another record when the current record cannot be saved (e.g. in the
AfterUpdate of an unbound navigation combo.)
 
D

doyle60

Thanks. I actually had it in the AfterUpdate of the form, not the
control. I changed it to the AfterUpdate of the control and I no
longer get the error but I did run into another problem. On this same
control code runs if you double click it (putting in today's date).
That caused our code here not to run. It only ran if they double
clicked and than took off a day.

So to make a long boring story short, I found it worked fine enough in
the OnExit of the control.

Thanks,

Matt
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top