PRB: CancelUpdate After AddNew Causes Error If Datatype Is Invalid (257790)
The information in this article applies to:
- Microsoft Visual Basic Learning Edition for Windows 6.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0 SP3
- ActiveX Data Objects (ADO) 2.0
- ActiveX Data Objects (ADO) 2.01
- ActiveX Data Objects (ADO) 2.1
- ActiveX Data Objects (ADO) 2.1 SP1
- ActiveX Data Objects (ADO) 2.1 SP2
- ActiveX Data Objects (ADO) 2.5
- ActiveX Data Objects (ADO) 2.6
- ActiveX Data Objects (ADO) 2.7
This article was previously published under Q257790 SYMPTOMS
If you add a new record to an ADO recordset by calling the AddNew method, enter data of an invalid datatype in a control bound to this recordset, and then cancel the change by calling the CancelUpdate method, the CancelUpdate method appears to generate an error due to the invalid datatype, and displays the following run-time error message if you are using ADO 2.1 SP2 or earlier:
Run-time error '-2147217842 (80040e4e)':
The change was canceled during notification; no columns are changed
If you are using ADO 2.5, then the error message may look like this:
Run-time error '-2147217842 (80040e4e)':
Operation was canceled.
This data validation makes sense when calling the Update method, but should not occur when canceling any changes that have been made.
RESOLUTION
To work around this problem, make sure that you enter a valid datatype. For example, using the above-mentioned sample, this unexpected validation error occurs when a string value is entered in a bound control where the underlying database is expecting a numeric value. To work around the error, you only need to check and fix the values that are entered in controls that are bound to numeric fields. The simplest approach is use the IsNumeric function to check the value that is entered in the control and, if the result is False, change the string in the control to a number. Because the record is not saved, the number that is chosen is not important.
To implement this workaround in the Visual Basic project that is described in the "Symptoms" section, add the following code to the CancelUpdate command button's Click procedure as follows:
Private Sub Command2_Click()
If Not IsNumeric(Text1.Text) Then
Text1.Text = 0 'Zero
End If
Adodc1.Recordset.CancelUpdate
End Sub
Modification Type: | Major | Last Reviewed: | 6/28/2004 |
---|
Keywords: | kbBug kbnofix kbprb KB257790 |
---|
|