Solved

Run-time error '3426'

Posted on 1997-11-10
14
419 Views
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.
0
Comment
Question by:JHosfield
  • 6
  • 4
  • 2
  • +2
14 Comments
 
LVL 1

Expert Comment

by:eyvind081997
Comment Utility
Try to set response = vbDataErrContinue      in the Data control error event?

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

Expert Comment

by:rantanen
Comment Utility
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.
0
 

Author Comment

by:JHosfield
Comment Utility
The Data control error event apparently never fires.  I tried your suggestion with out success.
0
 
LVL 1

Expert Comment

by:aprasrl
Comment Utility
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
0
 
LVL 4

Expert Comment

by:rantanen
Comment Utility
Hi,

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

    Data1.Recordset.Delete
    Data1.Recordset.MoveNext
    If Data1.Recordset.EOF Then
        Data1.Recordset.MovePrevious
    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.Refresh
    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.
0
 

Author Comment

by:JHosfield
Comment Utility
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.
0
 

Author Comment

by:JHosfield
Comment Utility
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.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 4

Expert Comment

by:rantanen
Comment Utility
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.
0
 

Author Comment

by:JHosfield
Comment Utility
Can you reproduce the error on your program?  If so, what is it that you did to produce the error?
0
 
LVL 4

Expert Comment

by:rantanen
Comment Utility
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.
0
 
LVL 6

Accepted Solution

by:
anthonyc earned 400 total points
Comment Utility
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.
0
 

Author Comment

by:JHosfield
Comment Utility
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.
0
 
LVL 6

Expert Comment

by:anthonyc
Comment Utility
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
0
 

Author Comment

by:JHosfield
Comment Utility
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.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now