Microsoft KB Archive/156550

= You receive a "Data Type Mismatch" error message when you set the ControlSource property of a combo box or a list box to a Date field type in Visual FoxPro =

Article ID: 156550

Article Last Modified on 2/12/2007

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 3.0b Standard Edition
 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 6.0 Professional Edition
 * Microsoft Visual FoxPro 7.0 Professional Edition
 * Microsoft Visual FoxPro 8.0 Professional Edition
 * Microsoft Visual FoxPro 9.0 Professional Edition

-



This article was previously published under Q156550



SYMPTOMS
In Microsoft Visual FoxPro, if you set the ControlSource property of a combo box or a list box to a Date field type, you receive the following error message at run time:

Error with -Value: Data Type Mismatch. Unbinding object



CAUSE
Combo boxes and list boxes handle only Character, Numeric, and Null data types. Other field types produce an error message when the form runs.



WORKAROUND
To work around this problem, use a SELECT-SQL statement to create an array, instead of setting the ControlSource property of a combo box or list box to a Date type field. Use the array in the RowSource property of the combo box or the list box. The DTOC function changes the data type from Date to Character. For example, to fix the example that is described in the "Steps to reproduce the behavior" section, you can use the following code in the Init method of the form: SELECT DTOC(order_date) FROM orders INTO ARRAY adates THISFORM.combo1.RowSource=THISFORM.combo1.RowSource In the Valid event of the combo box or the list box, use a REPLACE statement, instead of the ControlSource property, to put the value in the other table: REPLACE employee.hire_date WITH CTOD(THISFORM.combo1.Value) The CTOD function converts the selection back into a Date data type.



STATUS
This behavior is by design.



MORE INFORMATION
Combo box and list box objects do not handle all data types in the ControlSource property. The ControlSource property of a combo box or list box object can contain only data types of Character, Numeric, or Null.

Steps to reproduce the behavior
 Create a form. Name the form test. Put the orders and employee tables from the Testdata database in the data environment of the form. Testdata is located in the Vfp\Samples\Data folder.

Note In Visual FoxPro 6.0, Sample data is located in the \\Program Files\Microsoft Visual Studio\Common\Samples\Data folder.  Add a combo box or list box to the form and set the following properties: ControlSource=employee.hire_date RowSource=orders.order_date RowSourceType=Fields  Run the form. You receive an error message.

Additional query words: kbdsd VFoxWin

Keywords: KB156550

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.