Full Version: Combo Box On Not In List
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
peaitch
On my form I have a combo box with an On Not In List Event. To insert the new data in to the appropriate table I build up a SQL string as follows:

'Build up the SQL string to add new data.
strSQL = "INSERT INTO [tblMy Table Name]([fldItemName]) " & _
"VALUES ('" & NewData & "');"

I then perform the action

DoCmd.RunSQL strSQL

This works OK until the new data contains and apostrophe eg "Fred's CD". The error message 3075 - Syntax error, missing operator is displayed.

How can I resolve this problem?

Thanking you in advance.
pH
R. Hicks
Try changing you SQL to:
CODE
strSQL = "INSERT INTO [tblMy Table Name]([fldItemName]) " & _
"VALUES ('" & Chr(34) & NewData & Chr(34) & "');"

RDH
peaitch
Dear Ricky

Thanks for your suggestion.

It resulted in another VBA error - but it pointed me in the right direction. The solution that worked is

'Build up the SQL string to add new data.
strSQL = "INSERT INTO [tblMy Table Name]([fldItemType]) " & _
"VALUES (" & Chr(34) & NewData & Chr(34) & ");"

Many thanks

pH
R. Hicks
Glad you got it going .. you are welcome .. wink.gif

RDH
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.