I'm glad you realized you need a form. You can't do the NotInList thing from a table.
First you'll need to create a table to hold the shipping company names. The list inside a combo box doesn't persist; as soon as you close the form or table, the list is gone, and along with it any new names that were added. So you need to save them in a table. Let's call the table Shippers, and the field name CompanyName.
Set your combo box's Row Source Type to Table/Query (the default). Set the Row Source to "SELECT CompanyName FROM Shippers ORDER BY CompanyName;". Set the Limit To List property to Yes. (This causes the NotInList event to fire. You'll use the NotInList event to add each new name to the Shippers table.)
Set the On Not in List property to "[Event Procedure]", and click the "..." button to create the event procedure.
Before continuing, if you're using Access 2000, choose Tools>References from the menu. In the References dialog, uncheck "Microsoft ActiveX Data Objects x.x Library". Then scroll down until you find Microsoft DAO 3.6 Object Library and check it. Click OK to close the dialog.
Add the following code to the module:
Code:
Private Sub cboShipper_NotInList(NewData As String, Response As Integer)
Dim db As Database
Beep
If MsgBox("Shipping company is not in the list. Add it?", _
vbYesNo Or vbQuestion, "Unknown shipping company") = vbYes Then
Set db = CurrentDb()
db.Execute "INSERT INTO Shippers (CompanyName) Values ('" & NewData & "');"
Set db = Nothing
Response = acDataErrAdded
Else
Response = acDataErrContinue
End If
End Sub
The MsgBox warns the user that the shipping company name wasn't found, giving them a chance to check for a misspelling. If you're starting out with an empty Shippers table, your users might get annoyed at getting this MsgBox almost all the time. If they nag you to remove it, you can just keep the 4 statements before the "Else" and get rid of the rest of the If statement, but it's their fault if they get the same company in there spelled 5 different ways.
Rick Sprague