Solved

Runtime error 3020. What to do?

Posted on 1998-05-07
7
624 Views
Last Modified: 2008-02-01
On running my app (VB5) I get a run-time error 3020: "update or CancelUpdate without AddNew or Edit".

What does this mean?
How can I detect it (I don't get the error when running in design mode)?
What to do with it?

On error resume next doesn't seem to work.
0
Comment
Question by:Diver
  • 4
  • 3
7 Comments
 
LVL 4

Accepted Solution

by:
zsi earned 200 total points
ID: 1443099
Diver,

This error occurs when you try to invoke the Update or CancelUpdate method on a database or recordset object.  Most likwely, you have opened a database/query and have tried to execute this method.  You might be having an error that causes you to jump to another location in your code (as instructed by an ON ERROR GOTO xxx statement) and you are executing the Update or CancelUpdate method there.  This error is occuring before you open the database/query/recordset for editing.

Hope this helps!
zsi
0
 
LVL 1

Author Comment

by:Diver
ID: 1443100
There is no on error goto statement in the code. And the sad thing is that I do not know where the error comes from.

What you told me here is absolutely true, but it won't help me that way.

Is there a way to find out where exactly the error occurs? And why is this error not occuring when running the code in design time?
0
 
LVL 4

Expert Comment

by:zsi
ID: 1443101
If the code is not too large, you can e-mail it to me at expert@zs.com and I will take a look at it.  Please tell me where the error is occuring (what routine).  

zsi
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 4

Expert Comment

by:zsi
ID: 1443102
Diver,

I took a look at your code and the solution is simple.

At the various points where you are invoking the UpdateRecord method of your datacontrol, insert the following code around it.

As an example, in your routine imgNext_Click:
     If (datSpeelrondeRS.Recordset.EditMode = dbEditAdd) or (datSpeelrondeRS.Recordset.EditMode = dbEditInProgress) Then
          datSpeelrondeRS.Recordset.Update
     End If

Here is more information on the EditMode property from the VB Help file.

zsi
====================================
Returns a value that indicates the state of editing for the current record.

Syntax

object.EditMode

The object placeholder represents an object expression that evaluates to an object in the Applies To list.

Return Values

The EditMode property returns the following values:

Value      Description

dbEditNone      No editing operation is in progress.
dbEditInProgress      Edit method has been invoked, and the current record is in the copy buffer.
dbEditAdd      AddNew method has been invoked, and the current record in the copy buffer is a new record that hasn't been saved in the database.

These constants are listed in the Data Access (DAO) object library in the Object Browser.

Remarks

The EditMode property is most useful when you want to depart from the default functionality of a Data control or if you aren't using a Data control with Visual Basic Professional Edition.  You can check the value of the EditMode property and the value of the action parameter in the Validate event procedure to determine whether to invoke the Update method.
You can also check to see if the LockEdits property setting is True and the EditMode property setting is dbEditInProgress to determine whether the current data page is locked.
0
 
LVL 1

Author Comment

by:Diver
ID: 1443103
Sorry to tell you, but it still doesn't work.
Some strange things happen here: when I click the imgNext I get the same error on the last click; when I invoke this same procedure from the tab key (lost focus event) I don't get the runtime error!
When I click imgExit, which is basically the same procedure as imgNext, ... no error!

Believe me, I'm quite desperate now. Can you imagine what's happening?

Thanks for your help.
0
 
LVL 4

Expert Comment

by:zsi
ID: 1443104
Diver,

In your imgNext.Click event, there is code that calls the Update method of the data control's recordset.  This code needs to be wrapped with the code explained above.

This update will not happen if you use the Tab key to get to the button (instead of clicking on it) because tabbing to a control does not invoke that control's Click event; only it's GotFocus event.  

As for the imgExit code - the recordset might not be in a state of "non-edit".  It is difficult to say as I cannot run your app here.

0
 
LVL 1

Author Comment

by:Diver
ID: 1443105
Thanks for your help.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question