SQL Syntax Error

R

Ray Todd Jr

Can someone please point out what I'm doing wrong here. I am getting error
3134 -Syntax Error in Insert Into Statement. This code is behind a form
using the after insert event.

By using the msgbox, I can confirm that the data is in fact correct,
however, I guess I obviously don't have the syntax correct.

Thanks,

Ray.

Dim strPropertyNote As String
Dim lngPropertyID As Long
Dim strSql As String

lngPropertyID = Me!txtPropertyID
strPropertyNote = "Property Added to Database on " & Now()

msgbox lngPropertyID & " " & strPropertyNote

strSql = "Insert into taPropertyNotes (PropertyID, Note) " & _
"values (" & lngPropertyID & ", '" & strPropertyNote & "')"

DoCmd.RunSQL strSql
 
G

Graham Mandeno

Hi Ray

My first suspicion is that strPropertyNote contains an apostrophe.

Try moving your MsgBox to just before the RunSQL:

MsgBox strSQL
 
R

Ray Todd Jr

Hey Graham:

I moved the msgbox as indicated and it shows that the variables are being
transferred to the code correctly.

There is are no apostrophe in the strPropertyNote. It is simple statement ...

"strPropertyNote = "Property Added to Database on " & Now()

Any other suggestions would be appreciated....

Thanks,

Ray.

Graham Mandeno said:
Hi Ray

My first suspicion is that strPropertyNote contains an apostrophe.

Try moving your MsgBox to just before the RunSQL:

MsgBox strSQL
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Ray Todd Jr said:
Can someone please point out what I'm doing wrong here. I am getting
error
3134 -Syntax Error in Insert Into Statement. This code is behind a form
using the after insert event.

By using the msgbox, I can confirm that the data is in fact correct,
however, I guess I obviously don't have the syntax correct.

Thanks,

Ray.

Dim strPropertyNote As String
Dim lngPropertyID As Long
Dim strSql As String

lngPropertyID = Me!txtPropertyID
strPropertyNote = "Property Added to Database on " & Now()

msgbox lngPropertyID & " " & strPropertyNote

strSql = "Insert into taPropertyNotes (PropertyID, Note) " & _
"values (" & lngPropertyID & ", '" & strPropertyNote & "')"

DoCmd.RunSQL strSql
 
G

Graham Mandeno

Hi Ray

Sorry, if I'd looked more closely at your code I'd have seen there could be
no apostrophe!

At a glance I can't see anything wrong with the SQL statement. It would
help if you post the contents of strSQL here. Before the RunSQL line,
insert:
Debug.Print strSQL

Then go to the Immediate window (Ctrl-G) and copy the text from there to
paste into your message. Don't try to retype what you see in the MsgBox.
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Ray Todd Jr said:
Hey Graham:

I moved the msgbox as indicated and it shows that the variables are being
transferred to the code correctly.

There is are no apostrophe in the strPropertyNote. It is simple statement
...

"strPropertyNote = "Property Added to Database on " & Now()

Any other suggestions would be appreciated....

Thanks,

Ray.

Graham Mandeno said:
Hi Ray

My first suspicion is that strPropertyNote contains an apostrophe.

Try moving your MsgBox to just before the RunSQL:

MsgBox strSQL
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Ray Todd Jr said:
Can someone please point out what I'm doing wrong here. I am getting
error
3134 -Syntax Error in Insert Into Statement. This code is behind a
form
using the after insert event.

By using the msgbox, I can confirm that the data is in fact correct,
however, I guess I obviously don't have the syntax correct.

Thanks,

Ray.

Dim strPropertyNote As String
Dim lngPropertyID As Long
Dim strSql As String

lngPropertyID = Me!txtPropertyID
strPropertyNote = "Property Added to Database on " & Now()

msgbox lngPropertyID & " " & strPropertyNote

strSql = "Insert into taPropertyNotes (PropertyID, Note) " & _
"values (" & lngPropertyID & ", '" & strPropertyNote & "')"

DoCmd.RunSQL strSql
 
R

Ray Todd Jr

Hello Graham:

Here it is copy and pasted....

Insert into taPropertyNotes (PropertyID, Note) values (27, 'Property Entered
Tax Sale on 4/22/2008 7:43:21 PM')

Thanks for your time and help....

Ray.


Graham Mandeno said:
Hi Ray

Sorry, if I'd looked more closely at your code I'd have seen there could be
no apostrophe!

At a glance I can't see anything wrong with the SQL statement. It would
help if you post the contents of strSQL here. Before the RunSQL line,
insert:
Debug.Print strSQL

Then go to the Immediate window (Ctrl-G) and copy the text from there to
paste into your message. Don't try to retype what you see in the MsgBox.
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Ray Todd Jr said:
Hey Graham:

I moved the msgbox as indicated and it shows that the variables are being
transferred to the code correctly.

There is are no apostrophe in the strPropertyNote. It is simple statement
...

"strPropertyNote = "Property Added to Database on " & Now()

Any other suggestions would be appreciated....

Thanks,

Ray.

Graham Mandeno said:
Hi Ray

My first suspicion is that strPropertyNote contains an apostrophe.

Try moving your MsgBox to just before the RunSQL:

MsgBox strSQL
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Can someone please point out what I'm doing wrong here. I am getting
error
3134 -Syntax Error in Insert Into Statement. This code is behind a
form
using the after insert event.

By using the msgbox, I can confirm that the data is in fact correct,
however, I guess I obviously don't have the syntax correct.

Thanks,

Ray.

Dim strPropertyNote As String
Dim lngPropertyID As Long
Dim strSql As String

lngPropertyID = Me!txtPropertyID
strPropertyNote = "Property Added to Database on " & Now()

msgbox lngPropertyID & " " & strPropertyNote

strSql = "Insert into taPropertyNotes (PropertyID, Note) " & _
"values (" & lngPropertyID & ", '" & strPropertyNote & "')"

DoCmd.RunSQL strSql
 
D

Dirk Goldgar

Ray Todd Jr said:
Hello Graham:

Here it is copy and pasted....

Insert into taPropertyNotes (PropertyID, Note) values (27, 'Property
Entered
Tax Sale on 4/22/2008 7:43:21 PM')

Thanks for your time and help....


"Note" is a reserved word. You have to enclose it in square brackets if you
want it to be accepted:

Insert into taPropertyNotes (PropertyID, [Note]) values (27, 'Property
Entered Tax Sale on 4/22/2008 7:43:21 PM')
 
R

Ray Todd Jr

That solved it....

Thanks Dirk and Graham....

Dirk Goldgar said:
Ray Todd Jr said:
Hello Graham:

Here it is copy and pasted....

Insert into taPropertyNotes (PropertyID, Note) values (27, 'Property
Entered
Tax Sale on 4/22/2008 7:43:21 PM')

Thanks for your time and help....


"Note" is a reserved word. You have to enclose it in square brackets if you
want it to be accepted:

Insert into taPropertyNotes (PropertyID, [Note]) values (27, 'Property
Entered Tax Sale on 4/22/2008 7:43:21 PM')



--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

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