C
cokeitis via AccessMonster.com
I have the code below on my form to allow users to add data to a table if
it's not in the list. The problem I'm having is that if the name that I'm
adding to the list have an apostrophe in it I get the following message
(syntax error - mission operator in query expression).
Can someone please tell me how to work around this...I have no idea.
Thanks
------------------------- CODE --------------------------------------
Private Sub cboCompanyName_NotInList(NewData As String, Response As Integer)
On Error GoTo Err_cboCompanyName
Dim ctl As Control
Set ctl = Screen.ActiveControl
If MsgBox("Do you want to add '" & NewData & "' to the list?", vbYesNo +
vbQuestion, "Add To List") = vbYes Then
CurrentDb.Execute "INSERT INTO tblCompany (Company) SELECT '" & NewData & "'"
Response = acDataErrAdded
Else
Response = acDataErrContinue
ctl.Undo
End If
Exit_cboCompanyName:
Set ctl = Nothing
Exit Sub
Err_cboCompanyName:
MsgBox Err.Number & ": " & Err.Description
Resume Exit_cboCompanyName
End Sub
it's not in the list. The problem I'm having is that if the name that I'm
adding to the list have an apostrophe in it I get the following message
(syntax error - mission operator in query expression).
Can someone please tell me how to work around this...I have no idea.
Thanks
------------------------- CODE --------------------------------------
Private Sub cboCompanyName_NotInList(NewData As String, Response As Integer)
On Error GoTo Err_cboCompanyName
Dim ctl As Control
Set ctl = Screen.ActiveControl
If MsgBox("Do you want to add '" & NewData & "' to the list?", vbYesNo +
vbQuestion, "Add To List") = vbYes Then
CurrentDb.Execute "INSERT INTO tblCompany (Company) SELECT '" & NewData & "'"
Response = acDataErrAdded
Else
Response = acDataErrContinue
ctl.Undo
End If
Exit_cboCompanyName:
Set ctl = Nothing
Exit Sub
Err_cboCompanyName:
MsgBox Err.Number & ": " & Err.Description
Resume Exit_cboCompanyName
End Sub