Question : Need to add names to the combo box

I have a combo box  (  Combo30  ) / control source =  OwnerID
Based on a query:   SELECT OwnerTbl.OID, OwnerTbl.Owner FROM OwnerTbl ORDER BY [Owner];

I need the (  OwnerTbl  )  to open so new names can be added when the user tries to input a name that is not in the list.  Now it just tells them that they have to use a name in the list.

Answer : Need to add names to the combo box

Here are a couple of examples also:

Example 1 - Inserting a new item directly into the lookup table behind the scenes ....
Private Sub cboCONTACT_ID_NotInList(NewData As String, Response As Integer)
Dim myVar
Dim ctl As Control
Dim lresponse As Long
Set ctl = Me.cboCONTACT_ID
If MsgBox(NewData & " is a new item.  Do you wish to add it to the combo box?", vbYesNo, "Add Item") = vbYes Then

   'add the new record
    CurrentDb.Execute "insert into tbl_contacts ( [contact_NAME] ) values ('" & NewData & "');"
    Response = acDataErrAdded
Else
    myVar = Me.cboCONTACT_ID
    Response = acDataErrContinue
    ctl.Undo
    End If

End Sub

Example 2 - 'Form2' is a simple form connected to the list table
Private Sub Combo1_NotInList(NewData As String, Response As Integer)

    If MsgBox(NewData & " is a new item.  Do you wish to add it to the combo box?") = vbYesNo Then
        DoCmd.OpenForm "Form2", , , , acFormAdd, acDialog, NewData
        Response = acDataErrAdded
    Else
        Response = acDataErrContinue
        Me.Combo1.Undo
    End If
   
End Sub

mx
Random Solutions  
 
programming4us programming4us