Combo Boxes on Tables/Forms are for inserting frequently used common values quickly and easily into Data Fields. The Source Data Values of the Combo Box comes from Table or Query. The User is expected to click on the Drop Down control of the Combo Box to display the list of items and select the required item to insert into the data field. The User can type Values into the Source Control of the Combo Box also.

The following two Property setting of Combo Box allows the User to select items from the available list only and prevents from entering invalid values directly into the Target Field:

  • Limit to List = Yes
  • On Not in List = [EventProcedure]

When the Limit to List Property Value is set to Yes you must select/type values available in the Combo Box list only and other values keyed in manually are not accepted in the Target Field. You must add new items into the Source Table of the Combo Box Control first before they can be used from the Combo Box.

For example, assume that you have a Table with a list of Fruits (only two items in the list now: Apple and Cherry) and you are using this list in a Combo Box on the Sales Form. When the Limit to List Property Value is set to Yes; you will not be allowed to enter the value Orange into the Target Field of the Combo Box.

When the On Not in List Property is set with an Event Procedure; it is executed when the User enters a new value (Orange) manually into the Target Field of the Combo Box. We can write Code in the Event Procedure to add the entered new value into the Combo Box Source Table directly (after taking confirmation from the User) and update the Combo Box on the Form.

This method can save time otherwise needed for opening and adding new items in the Combo Box source Table directly. Besides that adding new values manually in the Source Table will not automatically refresh the Combo Box contents.

Let us try this out using the above example items as Source Data.

  1. Create a new Table with a single Field Name: Fruit and select the Data Type Text.
  2. Save the Table Structure with the name: FruitList.
  3. Open the Table in Datasheet View and key-in Apple and Cherry as two records.
  4. Close and Save the Table with the records.
  5. Create another Table with the following Structure:

    Table Structure
    Field Name Data Type Size
    ID AutoNumber
    Description Text 50
    Quantity Numeric Long Integer
    UnitPrice Numeric Double
  6. Before saving the Structure click on the second Field Data Type (Text) Column to select it.
  7. Click on the Lookup Tab on the Property Sheet below.


  8. Click on the Display Control Property and select Combo Box from the drop-down control.
  9. The Row Source Type Property Value will be Table/Query, if it is not then select it from the drop-down control.
  10. Click on the drop-down control of the Row Source Property and select the Table FruitList from the displayed list of Tables.
  11. Change Column Width Property and List Width Property Values to 1".
  12. Change the Limit to List Property Value to Yes.
  13. Save the Table Structure with the name Sales.
  14. Open the Table in Datasheet View and add a record with Apple, 100 and 1.5 in Description, Quantity and UnitPrice Fields respectively.
  15. Close and save the Table with the record.
  16. Click on the Sales Table to select it and select Form from Insert Menu.
  17. Create a Form using the Form Wizard in Column Format and save the Form with the name Sales.
  18. Open the Sales Form in normal view.

    Since, we have added the Combo Box on the Table Structure it is already appeared on the form.

  19. Press Ctrl++ (or click on New Record control on the Record Navigation control) to add a new blank record on the Form.
  20. Click on the drop-down control of the Combo Box and you will find the list of fruits: Apple and Cherry in it.
  21. But, you Key-in Orange into the Description field and press Enter Key.

    You will be greeted with the following error message:


    If you want to enter the value Orange on the Form, first you must add that item into the FruitList Table.

  22. Open the FruitList Table and add Orange as a new record and close the Table.

But, this action will not refresh the Combo Box contents automatically to add Orange into the list. You have to close the Sales form and open it again before you are able to select Orange from the list. Or you must add a Command Button on the Form and write Code to Re-Query the Combo Box contents.

What we did manually in response to the above error message can be automated by writing a VBA Routine that can be run through the On Not in List Event Procedure. You don't need to close and open the Form to refresh the Combo Box contents either.

  1. Open the Sales Form in Design View.
  2. Click on the Description Field to select the Combo Box control.
  3. Display the Property Sheet (View – -> Properties).
  4. Find and Click on the On Not in List Property.
  5. Select EventProcedure from the drop-down list.
  6. Click on the build button (. . .) to open the VBA Module.
  7. Copy and paste the following Code into the Module overwriting the top and bottom Procedure lines already appearing in the Module:
    Private Sub Description_NotInList(NewData As String, Response As Integer)
    Dim strmsg As String, rst As Recordset, db As Database
    If Response Then
        strmsg = "Entered Item not in List!" & vbCr & vbCr & "Add to List...?"
          If MsgBox(strmsg, vbYesNo + vbDefaultButton2 + vbQuestion, "Not in List") = vbYes Then
           Set db = CurrentDb
           Set rst = db.OpenRecordset("FruitList", dbOpenDynaset)
           rst![Fruit] = NewData
           Me![Description] = NewData
        End If
        Response = 0
    End If
    End Sub
  8. Save and Close the Sales Form.
  9. Open it in normal view.
  10. Now, type the name of any fruit that is not in the Combo Box list (say Peach) in the Description Field.

    You will be greeted with the following Message Box:


  11. Click the Command Button with the Label Yes to add the new item keyed in the Description Field into the FruitList Table and refresh the Combo Box List automatically.
  12. Now, click on the drop-down control of the Combo Box and you can see that the new item is added into the list and accepted in the Description Field as well.