I cannot see the syntax error - guidance please.

B

Billp

Hi,

Error 3134 Syntax error in INSERT INTO

str1 = ParseWord(Me![Contact Name], 1)
str2 = ParseWord(Me![Contact Name], -1)

strsql = "INSERT INTO [tblCUSTCONTACTS] [FIRST_NAME], [LAST_NAME] " _
& " VALUES (" & str1 & ", " & str2 &
")" _
& " WHERE [CustID] = " & Me![CustID]
Debug.Print strsql
DBEngine(0)(0).Execute strsql, dbFailOnError

Print out is

INSERT INTO [tblCUSTCONTACTS] [FIRST_NAME], [LAST_NAME] VALUES (Fergie,
Fred) WHERE [CustID] = 1391


Any help appreciated
 
D

Daniel Pineault

You need quote around your values.

INSERT INTO [tblCUSTCONTACTS] [FIRST_NAME], [LAST_NAME] VALUES ("Fergie",
"Fred") WHERE [CustID] = 1391

Use the query designer and look at the sql statement synthax, then you can
compare to your vba and easily spot problems. Just a tip.
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.
 
J

John Spencer

strsql = "INSERT INTO [tblCUSTCONTACTS] ( [FIRST_NAME], [LAST_NAME] ) " _
& " VALUES (""" & str1 & """, """ & str2 & """)" _
& " WHERE [CustID] = " & Me![CustID]

Assumption is that CustID is a number field. If it is a text field then you
will need some more quotes.

strsql = "INSERT INTO [tblCUSTCONTACTS] ( [FIRST_NAME], [LAST_NAME] ) " _
& " VALUES (""" & str1 & """, """ & str2 & """)" _
& " WHERE [CustID] = """ & Me![CustID] & """"

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 

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