Adding Data to a Combo Box - when Not In List
Jun 23 2008, 05:35 PM
From: South coast, England
The attached code samples show how to automatically add a new record to the table that forms the
Row Source of a combo box when the data typed into the combo box is ‘Not in the List’
There is a common code module that does the work and, apart from adding this code module to your DB, all
you have to do is add a single line of code to the ‘On Not in List’ event of each combo box where you want
to add new data.
Response = AddNewToList(NewData, "TableName", "FieldName")
Where ‘TableName’ is the name of the combo box row source’s underlying table
And ‘FieldName’ is the name of the field in table ‘TableName’ you want to add the new record to.
Gord Hubbell suggested similar code that was originally presented in 2001 but was not carried through to UA.
Thanks also to both Walter Niesz and CyberCow who pointed out some improvements in my original submission.
In this latest version, improvements suggested by Alan_G and Doug Steele have been included. These cater for
field names with spaces (which you should avoid anyway!), and allow apostrophe’s to be included in the new data.
The attachment has versions for A2000, A2003 and A2007.
Edit: Text and attachments changed at request of Author.
Edited by: LPurvis on Thu Jul 24 6:06:02 EDT 2008.
ComboNotInList V2.zip ( 59.16K ) Number of downloads: 462
|Go to Top · Lo-Fi Version||Time is now: 25th May 2013 - 03:53 AM|