syntax error (missing operator) in query expression

P

p-rat

I have a NotInList that is not working. If I enter in something in the
text box such as SALTY'S #3 it will return the error. If I take out
the single quote it works fine. It is suppose to accept the new text
and add it to the list. Here is the code:

Private Sub Disposal_Site_NotInList(NewData As String, Response As
Integer)
Dim sqlAddState As String, UserResponse As Integer
Beep
UserResponse = MsgBox("Do you want to add this value to the list?",
vbYesNo)
If UserResponse = vbYes Then
sqlAddState = "Insert Into DisposalSite ([DisposalSite])
values ('" & NewData & "')"
CurrentDb.Execute sqlAddState, dbFailOnError
Response = acDataErrAdded
Else
Response = acDataErrContinue
End If
End Sub


I think this is something simple, but being a beginner I can't figure
it out. Thanks.
 
B

Beetle

Modify the query like;

sqlAddState = "Insert Into DisposalSite ([DisposalSite])
values (""" & NewData & """)"

replacing each single quote with two double quotes so it won't hang
when there is an apostrophe in the name.
 

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