Results 1 to 8 of 8

Thread: Error on Adding Entry

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2003
    Posts
    13

    Error on Adding Entry

    my add was functioning properly when after sometime, it started to have this error. it says
    "This Event was cancelled by an associated object"


    i dont know what triggered this but i tried to search for it and i think i have not put somthing on my code to make this error happen.

    here is my code:
    On Error GoTo adderr
    Data1.Recordset.AddNew
    save.Enabled = True
    cmdsave.Enabled = True
    txtln.SetFocus
    Exit Sub
    adderr:
    MsgBox Err.Description

    ^ ^ i can see nothing wrong with it.

    can you share me the possibilities which may have caused the error?

    this also comes out when i move to another record.

    what could be wrong?

    thank you. please be patient with me. i am just starting with vB.
    thanks!

  2. #2
    Addicted Member
    Join Date
    Sep 2003
    Posts
    160
    Article ID: Q149040
    The information in this article applies to:
    Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 16-bit and 32-bit, for Windows, version 4.0


    SYMPTOMS
    If a Recordset.Update is issued without first issuing an AddNew or an Edit method, Visual Basic 4.0 correctly raises an error, because the Update method can only be invoked after an AddNew or an Edit method. However, the error number raised by the 16-bit and 32-bit editions of Visual Basic differs.

    The 32-bit edition of Visual Basic version 4.0 for Windows returns the following error:


    '3020' - Update or CancelUpdate without AddNew or Edit


    The 16-bit edition of Visual Basic version 4.0 for Windows returns the following error:

    '3426' - The action was cancelled by an associated object


    STATUS
    Microsoft has confirmed this to be an issue in the Microsoft products listed at the beginning of this article. Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.



    MORE INFORMATION


    Steps To Reproduce Problem

    Start the 32-bit edition of Visual Basic version 4.0 for Windows. Form1 is created by default.

    Add a single text box and data control to the form.

    Set the properties of the data control to the following:

    DatabaseName: BIBLIO.MDB
    RecordSource: Authors



    Set the properties of the text box to the following:

    DataSource: Data1
    DataField: Au_ID



    Add the following code to the Form_Click event of Form1:


    Private Sub Form_Click()
    Data1.Recordset.Update
    End Sub



    Press F5 or click Start on the Run menu to run the application. Change the text in the text box and click the form. With the 32-bit version of Visual Basic version 4.0 for Windows, error '3020' is raised. If these steps are repeated with the 16-bit version of Visual Basic version 4.0 for Windows, the error raised is '3426'.

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2003
    Posts
    13
    thanks man.

    but mines on .AddNew.
    it was working fine sometime ago but after adding a few code,
    it started to give this error msg.

    what will i do to fix it?

    thanks.

  4. #4
    Addicted Member
    Join Date
    Sep 2003
    Posts
    160
    so please give us complete code of your project reffering database part and tell us where exactly error happen and what you have added and you're using what kind of database?

    S. Mohammad Najafi

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2003
    Posts
    13
    i decided to use ADO.

    heres my code...

    VB Code:
    1. Private Sub Adodc1_WillChangeRecord(ByVal adReason As ADODB.EventReasonEnum, ByVal cRecords As Long, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
    2.  
    3.          
    4.     'pilyido
    5.     If txtln = "" Then
    6.     g = MsgBox("You must enter last name!")
    7.     txtln.SetFocus
    8.     GoTo gordonsupertechnique
    9.     Exit Sub
    10.  
    11. ....
    12.  
    13.  
    14. ElseIf txtrn = "" Then
    15.     w = MsgBox("Must enter a record number!")
    16.     txtrn.SetFocus
    17.     GoTo gordonsupertechnique
    18.     Exit Sub
    19.    
    20.     End If
    21.    
    22.  
    23. Exit Sub
    24. gordonsupertechnique:
    25.   adStatus = adStatusCancel
    26.  
    27.  
    28. End Sub

    the problem with this is that the validation code runs or a msgbox appears even when i press the tab button. i only need it to run when i add or delete or update or stuff like that. how could i do it?

  6. #6
    Addicted Member
    Join Date
    Sep 2003
    Posts
    160
    will then load your ado recordset in Batchoptimistic mode and add this code your willmove event of ado, what you will have to do is send .updatbatch for everytime you add new or update or delete records and you can do validation only when user accept it.

  7. #7

    Thread Starter
    New Member
    Join Date
    Sep 2003
    Posts
    13
    whats BatchOptimistic mode?

  8. #8
    Addicted Member
    Join Date
    Sep 2003
    Posts
    160
    adLockBatchOptimistic 4 Indicates optimistic batch updates. Required for batch update mode.

    adLockOptimistic 3 Indicates optimistic locking, record by record. The provider uses optimistic locking, locking records only when you call the Update method.

    adLockPessimistic 2 Indicates pessimistic locking, record by record. The provider does what is necessary to ensure successful editing of the records, usually by locking records at the data source immediately after editing.

    adLockReadOnly 1 Indicates read-only records. You cannot alter the data.

    adLockUnspecified -1 Does not specify a type of lock. For clones, the clone is created with the same lock type as the original.

    you should take a look at msdn buddy for sometimes (F1)

    S. Mohammad Najafi

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width