[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 437
  • Last Modified:

Run-time error '3426'

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
JHosfield
Asked:
JHosfield
  • 6
  • 4
  • 2
  • +2
1 Solution
 
eyvind081997Commented:
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
 
rantanenCommented:
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
 
JHosfieldAuthor Commented:
The Data control error event apparently never fires.  I tried your suggestion with out success.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
aprasrlCommented:
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
 
rantanenCommented:
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
 
JHosfieldAuthor Commented:
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
 
JHosfieldAuthor Commented:
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
 
rantanenCommented:
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
 
JHosfieldAuthor Commented:
Can you reproduce the error on your program?  If so, what is it that you did to produce the error?
0
 
rantanenCommented:
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
 
anthonycCommented:
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
 
JHosfieldAuthor Commented:
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
 
anthonycCommented:
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
 
JHosfieldAuthor Commented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 6
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now