You should not be using a value list as the control's RowSourceType property, but Table/Query. A value list should only be used for sets of values which are immutably fixed in the external world, e.g. days of the week or months of the year. The locations
should be stored in a table like this:
Locations
….LocationID (autonumber PK)
….Location (short text)
You can then use the following as the control's RowSource property:
SELECT LocationID, Location FROM Location ORDER BY Location;
The control's other properties should be:
ControlSource: LocationID
BoundColumn: 1
ColumnCount: 2
ColumnWidths: 0
By setting the ColumnWidths value to zero this hides the first column, so that only the location names are shown, but the value of the control is the numeric LocationID.
The referencing table into which the combo box is used to insert a value should contain an LocationID column of long integer data type in place of the current text column. Firstly add this to the table design and save the table. Then update the table with
the following 'update' query:
UPDATE [TableNameGoesHere] INNER JOIN Locations
ON [TableNameGoesHere].Location = Locations.Location
SET [TableNameGoesHere].LocationID = Locations.LocationID;
where Location is the name of the text column in the current table.
Top add a new location to the list put the following code in the control's NotInList event procedure:
Dim ctrl As Control
Dim strSQL As String, strMessage As String
Set ctrl = Me.ActiveControl
strMessage = "Add " & NewData & " to list?"
strSQL = "INSERT INTO Locations(Location) VALUES(""" & _
NewData & """)"
If MsgBox(strMessage, vbYesNo + vbQuestion) = vbYes Then
CurrentDB.Execute strSQL, dbFailOnError
Response = acDataErrAdded
Else
Response = acDataErrContinue
ctrl.Undo
End If