I am using the following code for adding to a Combo Box when an item is
entered that's not in the list:
Private Sub Customer_NotInList(NewData As String, Response As Integer)
On Error GoTo Customer_NotInList_Err
Dim intAnswer As Integer
Dim strSQL As String
intAnswer = MsgBox("Customer " & Chr(34) & NewData & _
Chr(34) & " does not exist." & vbCrLf & _
"Would you like to add it?" _
, vbQuestion + vbYesNo, "Customers")
If intAnswer = vbYes Then
strSQL = "INSERT INTO Customers_Table(CU_Customer) " & _
"VALUES ('" & NewData & "');"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
MsgBox "The new customer has been added." _
, vbInformation, "Customers"
Response = acDataErrAdded
Else
MsgBox "Please choose an existing customer then." _
, vbInformation, "Customers"
Response = acDataErrContinue
End If
Customer_NotInList_Exit:
Exit Sub
Customer_NotInList_Err:
MsgBox Err.Description, vbCritical, "Error"
Resume Customer_NotInList_Exit
End Sub
It's not working and I'm not sure why... When I type a new value into my
form I get the "Customer ___ does not exist. Would you like to add it?"
message. If I select No, I get the proper message. If I select yes, it
doesn't add it to the table. Instead I get the follow error message:
Cannot find output table 'Customers_Table'.
But that is the name of my table!
John Spencer - 06 Jun 2006 21:17 GMT
Try adding a space between Customers_Table and (CU_Customer)
strSQL = "INSERT INTO Customers_Table (CU_Customer) " & _
"VALUES ('" & NewData & "');"
Double check the name of the table. Is it Customers or is it
Customer_Table or is it Customers Table? If the last, try [Customers Table]
in the query string.
>I am using the following code for adding to a Combo Box when an item is
> entered that's not in the list:
[quoted text clipped - 36 lines]
>
> But that is the name of my table!
Christian ><> - 06 Jun 2006 21:28 GMT
I had the name right and I had tried the space before... THE BRACKETS
WORKED! THANK YOU!!!!!
> Try adding a space between Customers_Table and (CU_Customer)
>
[quoted text clipped - 45 lines]
> >
> > But that is the name of my table!