We help IT Professionals succeed at work.

Run-time error '3426'

JHosfield asked
Medium Priority
Last Modified: 2008-03-17
My project has a data control with several currency fields displayed. When the record changes or one of the fields change, a subroutine is fired which recalculate the sum of these fields.  The run-time error occurs when I use the delete method to remove a record and then use the MoveNext or MovePrevious command.  The error message says "This action was cancelled by an associated object."  Pressing the Help button gives a message stating that there is no documentation of this error. If I remove the Move command and use only delete, I can't change records using the data control. The only was I can get it to work at all is to use the Refresh method after the delete command but this resets the recordset back to the first record which is not what I want it to do.  I'm using VB 5.0 and this is an upgrade of a version of the same program that worked fine in VB 3.
Watch Question

Try to set response = vbDataErrContinue      in the Data control error event?

You can also print the error code here, so you know whats wrong.

Two things,

it is possible write a delete procedure which works without any errors using VB 5 (SP2) and Data Control.

Secondly, it is also possible to write a Refresh method which remembers the last position (previous or next if used with delete method). Mainly Refresh method is meant for multi-user apps.


The Data control error event apparently never fires.  I tried your suggestion with out success.

The error is generated by a "bound" control which currently has (holds) a value of the record you need to delete, try to put an
"invisible" control on your form and to set the focus to this control BEFORE performing any other operation on the data


I don't know your setup but following works just fine for me.

    If Data1.Recordset.EOF Then
    End If

When repositioning after Refresh do something like

    Dim nOldRecordsetType As Integer
    Dim nIndex As Integer
    nOldRecordsetType = Data1.RecordsetType
    If Data1.RecordsetType <> vbRSTypeTable Then
        Data1.RecordsetType = vbRSTypeTable
    End If
    nIndex = Data1.Recordset.Fields("TestField1").Value
    Data1.Recordset.Index = "MyIndex"
    Data1.Recordset.Seek "=", nIndex
    Data1.RecordsetType = nOldRecordsetType

This example assumes that you have a index containing one integer field. Modify as needed.

If these don't work for you then it would be very beneficial to see some source code,

I have used those snippets over and over again.


The delete code you are suggesting is what I started with.  The only way this will not generate an error is if I remove the recalc subroutine from all events associate with the fields and the data control.


To: aprasrl

The delete method isn't tripping the error.  It's the Move method that can't execute.  The focus should be on the delete control itself which is not a bound control.

I understood your problem as follows:

You have a form where you have some bound textboxes and one into which you calculate the sum of values in other textboxes. Is that correct?

If that is the case I use the simple delete code I mailed. In addition to that I do following things:

Automatic update of values thru repositioning the data control is prevented. So it is used only for browsing.

All textboxes are read only. If user wants to add/edit a record he/she must make a menu/toolbar selection, which  disables everything else except Update/Cancel selections and enables those textboxes.

Recalculation is fired thru Change events in text boxes.

This method works just fine for me.


Can you reproduce the error on your program?  If so, what is it that you did to produce the error?

I don't remember what was happening when I first time decided this is the way I do it. Now when I at will try to produce this error, I quickly came up only one situation:

If I store the value of the calculated field also in the database and try to delete the last record or I try to add the first record into an empty database, I get this error.

So the thing in this case is not to store the value of the calculated field.
What seems to be happening here is that your update of the calculated field is firing an EDIT method (internally, via the data control), while the move is in progress.  This edit is being canceled.

While I suggest never saving calculated values in a database, sometimes this may be necessary for speed.  I would suggest always calculating this value whereever you need it, but if you really want to do it this way, try this:

1)  Calculate the value in a UNBOUND field.  Therefore, no data control events will cause it not to work.

2)  In the VALIDATE event of the data control, write code to save the value.  You can do this via code, OR you can add another text box to your application, make it invisible, and set this value when the SAVE parameter of the validate event is set.  

This will fix your problem because no updates will be made to the calculated field unless they are absolutely necessary.  The visible calculated field will be updated all the time, allowing the users to see the results.

Try this and let me know what you think.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


The calculated field is not bound to the data control.  The fields containing the values which comprise the sum displayed in the calculated field are bound.  These fields each have a change event in which a sub is fired which then recalculates the sum.  The only way to prevent the problem is to clear the change events for all bound fields but then the sum is not recalculated when a change is made to the field.

Ok I suspect your problem is that you are passing the values to the calculating sub, then the values are changing.  Try making each parameter to the calculating sub BYVAL


ByVal only works with functions.  The sub-rountine picks up the value directly from the fields.  This sounded like a good idea however, so I converted the sub to a function and passed the fields using the byVal qualifier per your suggestion but the results were the same.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.