Hello all
I have tried searching for a solution to my problem but still can't figure it out.
I have a form with a combo box on called Type which is linked to the field Type in a table called tbCommunications, the Type field in the tbCommunications table is a lookup field which gets its list from a table called tbCommunication Types.
Basically I have the following code in the notinlist event for the combo box Type so that a user can choose to add their entry to the list.
However when i run the code i get the message 'syntax error in the INSERT INTO statement.
Note: I got the original code for this from http://www.fontstuff.com/access/acctut20.htm
Can anyone help?
Niyx
I have tried searching for a solution to my problem but still can't figure it out.
I have a form with a combo box on called Type which is linked to the field Type in a table called tbCommunications, the Type field in the tbCommunications table is a lookup field which gets its list from a table called tbCommunication Types.
Basically I have the following code in the notinlist event for the combo box Type so that a user can choose to add their entry to the list.
Code:
Private Sub Type_NotInList(NewData As String, Response As Integer)
On Error GoTo Type_NotInList_Err
Dim intAnswer As Integer
Dim strSQL As String
intAnswer = MsgBox("The communication type " & Chr(34) & NewData & _
Chr(34) & " is not currently listed." & vbCrLf & _
"Would you like to add it to the list now?" _
, vbQuestion + vbYesNo, "Partnerships - Communications")
If intAnswer = vbYes Then
strSQL = "INSERT INTO tbCommunication Types([Communication Type]) " _
& "VALUES ('" & NewData & "');"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
MsgBox "The new communication type has been added to the list." _
, vbInformation, "Partnerships - Communications"
Response = acDataErrAdded
Else
MsgBox "Please choose communication type from the list." _
, vbInformation, "Partnerships - Communications"
Response = acDataErrContinue
End If
Type_NotInList_Exit:
Exit Sub
Type_NotInList_Err:
MsgBox Err.Description, vbCritical, "Error"
Resume Type_NotInList_Exit
However when i run the code i get the message 'syntax error in the INSERT INTO statement.
Note: I got the original code for this from http://www.fontstuff.com/access/acctut20.htm
Can anyone help?
Niyx