Not In List Event--Adding to Table

G

Guest

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!
 
J

John Spencer

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.
 
G

Guest

I had the name right and I had tried the space before... THE BRACKETS
WORKED! THANK YOU!!!!!

John Spencer said:
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.

Christian > said:
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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top