Adding new item using combo box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have deveopled a form with a number of comboxes. The CBs will display the
records from an underlying table without problem however I need to now how to
add a record to those tables when the user types information that does not
already exists.

CmBx: Name - lists all names in the underlying table
When a new name is entered/typed and it is not present in the underlying
table can access automatically add it?

Not sure if I am being clear however any help would be great.
 
I have deveopled a form with a number of comboxes. The CBs will display the
records from an underlying table without problem however I need to now how to
add a record to those tables when the user types information that does not
already exists.

CmBx: Name - lists all names in the underlying table
When a new name is entered/typed and it is not present in the underlying
table can access automatically add it?

Not sure if I am being clear however any help would be great.

Is the name the only item you have to fill in when you add it?

Code the Combo Box NotInList event:

If MsgBox("Name is not in list. Add it?", vbOKCancel) = vbOK Then
Dim strSQL As String
strSQL = " INSERT INTO YourTable(NameField) SELECT """ & NewData &
""";"

CurrentDb.Execute strSQL, dbFailOnError
Response = acDataErrAdded
Else
' If user chooses Cancel, suppress error message
Response = acDataErrContinue
End If

Note: If your field name is really Name, Name is an Access reserved
keyword and should not be used as a field name.
 
Back
Top