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