Microsoft KB Archive/172101: Difference between revisions
(importing KB archive) |
m (Text replacement - """ to """) |
||
Line 12: | Line 12: | ||
<div id="TitleRow"> | <div id="TitleRow"> | ||
= <span id="KB172101"></span>PRB: | = <span id="KB172101"></span>PRB: "Data Type Conversion Error" When Using a Data Control = | ||
Line 54: | Line 54: | ||
<div class="errormessage"> | <div class="errormessage"> | ||
"Data Type Conversion Error." | |||
</div> | </div> | ||
Line 67: | Line 67: | ||
This is designed behavior of DAO. The data control is sending a NULL string to DAO and DAO attempts to coerce it to a number and fails. This is not a problem with the Data Control: The same behavior can be observed without the use of a Data Control, using only code. For example:<br /> | This is designed behavior of DAO. The data control is sending a NULL string to DAO and DAO attempts to coerce it to a number and fails. This is not a problem with the Data Control: The same behavior can be observed without the use of a Data Control, using only code. For example:<br /> | ||
<pre class="codesample"> Set db = OpenDatabase( | <pre class="codesample"> Set db = OpenDatabase("nwind.mdb", False, False) | ||
Set rs = db.OpenRecordset( | Set rs = db.OpenRecordset("select shipvia from orders", dbOpenDynaset) | ||
rs.Edit | rs.Edit | ||
rs(0) = | rs(0) = "" | ||
</pre> | </pre> | ||
Line 111: | Line 111: | ||
# Bind the textbox to an integer column of a table. | # Bind the textbox to an integer column of a table. | ||
# Delete the data from the text box. | # Delete the data from the text box. | ||
# Move off the record. Note that you get the | # Move off the record. Note that you get the "data type conversion error in the error event of the data control. This happens with Jet 3.5, 3.0, or 2.5, but does not happen in 16-bit Visual Basic. | ||
Latest revision as of 11:06, 21 July 2020
Article ID: 172101
Article Last Modified on 6/28/2004
APPLIES TO
- Microsoft Visual Basic 5.0 Professional Edition
- Microsoft Visual Basic 6.0 Professional Edition
- Microsoft Visual Basic 5.0 Enterprise Edition
- Microsoft Visual Basic 6.0 Enterprise Edition
- Microsoft Visual Basic 4.0 Standard Edition
- Microsoft Visual Basic 4.0 Professional Edition
- Microsoft Visual Basic 4.0 32-Bit Enterprise Edition
This article was previously published under Q172101
SYMPTOMS
Deleting the data from a text box bound to certain data types, such as an integer or date, causes Error 3421:
NOTE: If you are using a dbGrid, it's Error Method will produce Error 16389.
CAUSE
This is designed behavior of DAO. The data control is sending a NULL string to DAO and DAO attempts to coerce it to a number and fails. This is not a problem with the Data Control: The same behavior can be observed without the use of a Data Control, using only code. For example:
Set db = OpenDatabase("nwind.mdb", False, False) Set rs = db.OpenRecordset("select shipvia from orders", dbOpenDynaset) rs.Edit rs(0) = ""
RESOLUTION
Use the following code in the Data Controls Validate method to allow the edit to occur as expected by user:
Private Sub Data1_Validate(Action As Integer, Save As Integer) If Text1.DataChanged Then Text1.DataChanged = False 'So this data is not saved Data1.UpdateRecord ' This saves the data that ' may have changed in the other controls ' Now clear the numeric field Data1.Recordset.Edit Data1.Recordset![Year Born] = Null Data1.Recordset.Update End If End Sub
STATUS
This behavior is by design.
MORE INFORMATION
Steps to Reproduce Behavior
- Place a data control and a textbox on a form.
- Bind the textbox to an integer column of a table.
- Delete the data from the text box.
- Move off the record. Note that you get the "data type conversion error in the error event of the data control. This happens with Jet 3.5, 3.0, or 2.5, but does not happen in 16-bit Visual Basic.
Additional query words: kbVBp500 kbVBp600 kbVBp kbdse kbDSupport kbVBp400 kbVS97
Keywords: kbprb KB172101