|
-
Sep 26th, 2003, 09:41 AM
#1
Thread Starter
New Member
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!
-
Sep 27th, 2003, 02:36 AM
#2
Addicted Member
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'.
-
Sep 27th, 2003, 03:49 AM
#3
Thread Starter
New Member
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.
-
Sep 27th, 2003, 04:12 AM
#4
Addicted Member
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
-
Sep 27th, 2003, 10:12 AM
#5
Thread Starter
New Member
i decided to use ADO.
heres my code...
VB Code:
Private Sub Adodc1_WillChangeRecord(ByVal adReason As ADODB.EventReasonEnum, ByVal cRecords As Long, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
'pilyido
If txtln = "" Then
g = MsgBox("You must enter last name!")
txtln.SetFocus
GoTo gordonsupertechnique
Exit Sub
....
ElseIf txtrn = "" Then
w = MsgBox("Must enter a record number!")
txtrn.SetFocus
GoTo gordonsupertechnique
Exit Sub
End If
Exit Sub
gordonsupertechnique:
adStatus = adStatusCancel
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?
-
Sep 27th, 2003, 10:21 AM
#6
Addicted Member
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.
-
Sep 27th, 2003, 11:07 AM
#7
Thread Starter
New Member
whats BatchOptimistic mode?
-
Sep 27th, 2003, 12:10 PM
#8
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|