Share via

Adding an item to a combo box stopped working

Robert Walberg 5 Reputation points
2026-01-07T06:45:44.0433333+00:00

I have a basic contact list table/form that includes a look up table for the Town field with 3 columns: TownID, Town, and PostalCode. I wrote code for the Town field in the After Event property that recognizes when a town is not in the table. The code prompts the user to enter the postal code for said new entry and adds this to the look up table (mostly small towns with a single postal code). All worked fine until it didn't. When I open an older version of the database, everything works as it should. But over time I made some changes to the form and with this new version all I get when new text is entered is a standard Access message (i.e., not of my making): "the text you entered isn't an item in the list". I've tried studying the older version but I didn't learn anything from that exercise. I put in a msgbox at the beginning of the code, and it doesn't appear. That tells me that after new text is entered, Access is going somewhere other than the After Event code. Can anyone help me out?

Microsoft 365 and Office | Access | For home | Windows

5 answers

Sort by: Most helpful
  1. Ken Sheridan 3,571 Reputation points
    2026-01-07T14:09:58.95+00:00

    The problem with using the NotInList event procedure for inserting a new town or city into the relevant referenced tables is that town and city names can legitimately be duplicated, so if a list box includes a town name in its list, this might not be the same town as a new one of the same name which you want to insert. In the table the two would have different primary key values of course, but this will usually be in a hidden column in a combo box's RowSource, so you'll only see the name in the list.

    One way to get round this is to use correlated combo boxes, so that the town or city combo box only lists those towns or cities in a region, e.g. a county , state or similar, selected in another combo box. You'll find an example of this in CorrelatedCombos.zip in my Dropbox public databases folder at: 

    https://www.dropbox.com/scl/fo/0scigd3r48hx5xrev2jrf/AB0-GMdTgMAO5O1cGdr3QW0?rlkey=ib6bs6g9jqcrywwzivur3265t&dl=0 

    In this little demo file a country, region, city, and postcode are selected in four correlated combo boxes, of which the first two are unbound, as to have columns in the the referencing Contacts table for these would introduce redundancy into the table. The demo also illustrates how to use the NotInList event procedure in this context, so that, as well as inserting the town or city name into the referenced Cities table, the correct RegionID value is also inserted.

    1 person found this answer helpful.
    0 comments No comments

  2. Gabriel-N 16,565 Reputation points Microsoft External Staff Moderator
    2026-01-07T08:04:19.3966667+00:00

    Dear Robert Walberg

    Thank you for posting your question in the Microsoft Q&A forum.

    I took a look at the combo box behavior you mentioned where Access still shows “The text you entered isn’t an item in the list” even after you add the Town. One thing that often causes this is the NotInList event not setting the Response value in a way that tells Access the new value has been handled. Could you try adding the lines in your code?

    ' After your DoCmd.RunSQL statement:
    MsgBox "Postal Code Added to CityTown Lookup Table", vbInformation
    Response = acDataErrAdded  ' This suppresses the Access error and refreshes the list
    
    

    Also, it would be worth double-checking the combo box setup. If the combo is bound to TownID (numeric) but NewData is the Town name (text), Access may still fail the re-check after the insert and show the built-in message again.

    If possible, could you share a small sanitized sample .accdb via private message so I can reproduce the issue and investigate more thoroughly?

    User's image

    Hope this helps. If you can share the sample, I’ll take a closer look and get back to you with specific recommendations.


    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

  3. Robert Walberg 5 Reputation points
    2026-01-18T10:40:28.4333333+00:00

    I spoke too soon. The new design and code worked as I wanted. Unfortunately, even within a very simple database, other problems arose. Not being well-versed on Access and especially VBA coding (learning on the go), I could not fix them in a timely manner (worst time of year-busy season) So, I worked on reverting to my earlier version. In other words, I'm back to square 1. For now, I manually add new data into the lookup table. Fortunately, the bulk of the data is already in the table. There are few new entries. When I have more time, I'll give it another go.

    Another downside that I encountered with the text box approach is that I have to type the whole city or town. With a combo box typing 1-3 letters gets you the city/town you want.

    One positive that came out of ths is that I now populate 3 field based on 1 field when recording a new contact, which is 1 more than before. Save some time and is more accurate.


  4. Robert Walberg 5 Reputation points
    2026-01-18T00:16:57.8333333+00:00

    Problem solved, I hope. I noticed that the older version that worked used a text box and not a combo box. After fiddling with the combo box approach, I decided to try the text box method.

    In the newer version, I added a field to the DonorT table with Data Type = Short Text (the combo box was linked to a number field). I switched out the combo box field with the text box field. The VBA code is all in the AfterEvent procedure, and it much the same as the older version.

    I also added a Province field to the CityTownT, so this table contains the City/Town, Province, and Postal Code field. When I enter a city or town and the data is already in the table, the 3 field are automatically populated. If the city or town is not found, the user is prompted for the information. Ultimately, the new data is entered into the look up table. I can post the code if anyone is interested.

    My question is, is this OK or am I setting myself up for future problems?

    0 comments No comments

  5. Q&A Assist
    2026-01-07T06:45:57.9633333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    It sounds like your issue with the combo box may stem from how the NotInList event is being triggered or handled in your updated form. Here are a few steps you can take to troubleshoot the problem:

    1. Check the LimitToList Property: Ensure that the LimitToList property of the combo box is set to Yes. This setting is crucial for the NotInList event to be triggered when a user enters a value that is not in the list.
    2. Review the Event Procedure: Make sure that the event procedure for the NotInList event is correctly set up. The procedure should handle the addition of new entries to the lookup table. If the procedure is missing or not correctly linked to the event, it won't execute.
    3. Debugging: Since you mentioned that the message box does not appear, it indicates that the code may not be executing at all. You can try placing breakpoints in your code to see if it hits the NotInList event when you enter a new town. This can help you determine if the event is firing as expected.
    4. Check for Changes in the Form: Since you mentioned making changes to the form, review those changes to see if anything might have inadvertently affected the combo box's behavior. For example, ensure that the combo box is still bound to the correct data source.
    5. Requery the Combo Box: After adding a new town to the lookup table, ensure you are using the Requery method to refresh the combo box list so that it includes the newly added value.

    If these steps do not resolve the issue, you may want to compare the properties of the working older version of the database with the new version to identify any discrepancies.


    References:

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.