Microsoft KB Archive/824176

= Error message when you programmatically add a new record to a table by using the NotInList event of the Combo Box on a form in Microsoft Access: &quot;The Text You Entered Isn't an Item in the List&quot; =

Article ID: 824176

Article Last Modified on 4/13/2007

-

APPLIES TO


 * Microsoft Office Access 2007
 * Microsoft Office Access 2003
 * Microsoft Access 2002 Standard Edition
 * Microsoft Access 2000 Standard Edition

-



This article applies only to a Microsoft Access database (.mdb).



For a Microsoft Access 97 version of this article, see 161007.

Moderate: Requires basic macro, coding, and interoperability skills.



SYMPTOMS
When you try to programmatically add a new record to a table by using the NotInList event of the combo box on a form, you might receive the following error message:

The text you entered isn't an item in the list.

Select an item from the list, or type the text that matches one of the listed items.

However, the new record is successfully added to the table. As a result, the new item that you entered is added to the list of items in the combo box.



CAUSE
This problem occurs when the combo box is bound to a Number data type column and the format property for the column is set to Currency or to Euro.



WORKAROUND
To work around this problem, type the value in the combo box that matches the format of the column that the combo box is bound to. For example, if the format of the column is Currency, type $20 instead of 20.

However, if the format of the column is set to Euro, you might not be able to enter a number that matches the format of the column.

Note If you reset the Format property of the column, the problem does not occur.



MORE INFORMATION
You might also receive the error message when you type a number that corresponds to an item in the combo box that already exists. This problem might occur if the number that you type does not match the formatted entries of the underlying recordset that already exists.

Steps to reproduce the behavior in Microsoft Office Access 2003
 Start Microsoft Access. Create a new Db1.mdb database. To create the required sample table, follow these steps:  In the Database window, click Tables under Objects. In the right pane, double-click Create table in Design view.</li> In the first row of the Field Name column, type ID, and then set the corresponding Data Type to AutoNumber.</li> In the second row of the Field Name column, type Rates, and then set the corresponding Data Type to Number.</li> In the Field Properties pane, click the General tab.</li> Set the Format property to Currency.</li> On the File menu, click Save.</li> In the Save As dialog box, type Rates, and then click OK.</li> On the File menu, click Close.</li></ol> </li> In the Database window, click Forms under Objects.</li> In the right pane, double-click Create form in Design view.</li> Add a ComboTest combo box to the form, and then set the properties as follows:

</li> On the View menu, click Code to open the Microsoft Visual Basic Editor.</li>  Paste the following code in the NotInList event of the ComboTest combo box. Note The sample code in this article uses Microsoft Data Access Objects. For this code to run correctly, you must reference the Microsoft DAO 3.6 Object Library. To do so, click References on the Tools menu in the Visual Basic Editor, and make sure that the Microsoft DAO 3.6 Object Library check box is selected. Dim Db As DAO.Database Dim Rs As DAO.Recordset Dim Msg As String Msg = &quot;'&quot; & NewData & &quot;' is not in the list.&quot; & vbCr & vbCr Msg = Msg & &quot;Do you want to add it?&quot; If MsgBox(Msg, vbQuestion + vbYesNo) = vbNo Then Response = acDataErrContinue MsgBox &quot;Try again.&quot; Else Set Db = CurrentDb Set Rs = Db.OpenRecordset(&quot;Rates&quot;, dbOpenDynaset)

Rs.AddNew Rs![Rates] = NewData Rs.Update Response = acDataErrAdded

End If </li> On the File menu, click Save.</li> In the Save As dialog box, type FormTest, and then click OK.</li> On the File menu, click Close.</li> In the right pane of the Database window, double-click FormTest.</li> <li>Type a number in the combo box, and then press the ENTER key.

The NotInList event is triggered. You receive the error message that is mentioned in the &quot;Symptoms&quot; section of this article.</li></ol>

<div class="references_section">