Combo box add new customer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • toolman
    New Member
    • Feb 2007
    • 1

    Combo box add new customer

    I have on a form a combo box that lists all my customers from a customers table.
    How do I add a new customer from this combo box? bearing in mind the form only displays the customers.
  • JamesDC
    New Member
    • Feb 2007
    • 66

    #2
    Originally posted by toolman
    I have on a form a combo box that lists all my customers from a customers table.
    How do I add a new customer from this combo box? bearing in mind the form only displays the customers.
    Add a text field somewhere on the form that add new records to the costumer table. That way the combobox will be updated with the new costumer's when they're put into the new field.

    I'm not sure if there is a way to do this directly in the combobox...

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      In the After Update event of the Combo box:
      Code:
      Private Combo_Box_Name_AfterUpdate()
      If DCount("*", "[Customer Table Name]", "[Customer Field Name] = '" & Me.[Combo_Box_Name] & "'") = 0 Then
         If MsgBox("Do You Wish To Add '" & Me.[Combo Box Name] & "' As A New Customer?", vkOKCancel) = vbOK Then
            DoCmd.SetWarnings False
            DoCmd.RunSQL "Insert Into [Customer Table Name] Values ('" & Me.[Combo Box Name] & "')"
            DoCmd.SetWarnings True
         End If
      End If
      End Sub

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32668

        #4
        Nice solution.
        The ComboBox would need the LimitToList property set to False for this to work.

        Comment

        • Rabbit
          Recognized Expert MVP
          • Jan 2007
          • 12517

          #5
          You'll also need to requery the combo box.

          Comment

          Working...