Solved

Mystic Error 3426

Posted on 1998-09-19
6
183 Views
Last Modified: 2010-04-30
I have a data control with 6 fields: 2 dates and 4 text fields, one of the latter is a filename.

I get the run-time error 3426 "This action was cancelled by an associated object". I'm using VB 5, and it has no documentation for that error. The error happens under the following circumstances:

1. A new database is created.
2. I use AddNew method on the recordset to create the very first record.
3. I fill some of the fields, among them the field with the filename.
4. The Update method is applied to the recordset.
5. I set the bookmark to the new record using ".Bookmark = .LastModified"

At that moment error 3426 happens.

Note that it does not happen if I don't fill the field with the filename or if the record is not the first.

0
Comment
Question by:karnovsk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 

Author Comment

by:karnovsk
ID: 1435632
Edited text of question
0
 

Author Comment

by:karnovsk
ID: 1435633
Error 3426 was already discussed in Experts Exchange  in November 1997 (QID=10028427), but the answers given there don't help me.
0
 
LVL 2

Expert Comment

by:dabellei
ID: 1435634
before doing your bookmark try to do a movelast this will repositionned you to the same record and then your bookmark will work
0
Technology Partners: 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!

 

Author Comment

by:karnovsk
ID: 1435635
Neither MoveLast nor MoveFirst help. Both generate the same error 3426.

General comment: I would be very grateful for a good workaround, but I would also like to get an indepth explanation of error 3426. Actually I am afraid that it is a Microsoft bug.
0
 
LVL 1

Accepted Solution

by:
steve06 earned 200 total points
ID: 1435636
From Microsoft site (it's not a bug, it's a feature!)

The information in this article applies to:
Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, versions 5.0, 6.0
Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 16-bit and 32-bit, for Windows, version 4.0


SYMPTOMS
This article discusses the error message "This action was cancelled by an associated object." that Visual Basic generates when working with Access databases and the Data control. This article does not apply to the ADO data control.



CAUSE
This error is being generated because the AddNew command of a bound recordset causes Visual Basic to try to save the current record if the data has changed. Because the data control is currently pointing to a NULL record and not an empty record, the data cannot be saved so the "action was cancelled by an associated object" error is reported. This is commonly seen when using the data form wizard in Visual Basic versions 4.0 and 5.0. The data form wizard in Visual Basic 6.0 generates code for the ADO data control so this error is less likely to occur.



RESOLUTION
Check the underlying recordset to see if either the BOF or EOF properties are True before allowing an implicit save to occur. An implicit save occurs either when using the data control to navigate off of a record where the information has changed or adding a record to a bound recordset.



STATUS
This behavior is by design.



MORE INFORMATION


Steps to Reproduce Behavior

Create a new Visual Basic Standard EXE project. Form1 is created by default.

Add the following controls to Form1:

      Control Type        Control Name         Caption
      ------------        ------------         -------
      Data                datDataCtl
      Text Box            txtCategory
      Command Button      cmdAddNew            Add
      Command Button      cmdMoveVeryLast      Move Very Last


Cut and paste the following code into the code window of the form:


      Option Explicit


      Private Sub cmdAddNew_Click()

          'Uncomment this block to avoid 3426 error message
          ' Check to see you are on NULL Pointer
          'If datDataCtl.Recordset.EOF Or datDataCtl.Recordset.BOF Then

              'Dim strBuffer As String

              ' Save what was typed into the text box into memory
              'strBuffer = txtCategory.Text

              ' Restore text box value to the original record contents
              ' in this case, that is NULL
              'datDataCtl.UpdateControls

              ' Add a new blank record
              'datDataCtl.Recordset.AddNew

              ' Restore what has been typed from memory to text box
              'txtCategory.Text = strBuffer

              ' Save the current record we are on and Add a new blank
              ' record
              'datDataCtl.Recordset.AddNew

          'End If

          ' be sure to comment below line when uncommenting above block of
          ' code to avoid an additional record added to the recordset.
          datDataCtl.Recordset.AddNew

      End Sub

      Private Sub cmdMoveVeryLast_Click()

        If Not (datDataCtl.Recordset.BOF Or datDataCtl.Recordset.EOF) Then
          datDataCtl.Recordset.MoveLast
          datDataCtl.Recordset.MoveNext
        End If

      End Sub

      Private Sub Form_Load()

          With datDataCtl
            .DatabaseName = App.Path & "\NWIND.MDB"
            .RecordSource = "Categories"
          End With

          txtCategory.DataField = "CategoryName"

      End Sub


While in the form's design view, set txtCategory's DataSource property equal to datDataCtl.

Run the form. To reproduce the data, click on the Move Very Last CommanButton, type any data into the text box, and then click on the Add CommandButton.

Note error: uncomment the above code sample to avoid the error.

Best regards,
Steve06
0
 

Author Comment

by:karnovsk
ID: 1435637
Thank you very much, steve06! I was looking for that type of an answer!
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

751 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