SQL issue (1 Viewer)

andy1968

Registered User.
Local time
Yesterday, 16:45
Joined
May 9, 2018
Messages
131
I have a simple problem that has me stumped.



I'm trying to add data to a table with an input into Sql string. I get a syntax error missing operator in the query expression '25r1'.


25r1 is the value of strCN.


lngID is a number, the other items are strings.



Code:
strSql = "INSERT INTO [tblSubmittalInfo] ( [SerialNumber], [ContractorNumber], [Reviewer] )Values(" & lngID & ", " & strCN & ", " & Me.Reviewer & " );"
                Debug.Print strSql


From the immediate window I get strSql =

INSERT INTO [tblSubmittalInfo] ( [SerialNumber], [ContractorNumber], [Reviewer] )Values(397, 25r1, Roberto Salinas );
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 07:45
Joined
May 7, 2009
Messages
19,230
Code:
trSql = "INSERT INTO [tblSubmittalInfo] ( [SerialNumber], [ContractorNumber], [Reviewer] )Values(" & lngID & ", " & Chr(34) & strCN & Chr(34) & ", " & Chr(34) & Me.Reviewer & Chr(34) & " );"
                Debug.Print strSql
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:45
Joined
Oct 29, 2018
Messages
21,467
Hi. Try delimiting your string values. For example:
Code:
...Values(" & lngID & ", '" & strCN & "', '" & Me.Reviewer & "' );"
Edit: Oops, too slow...
 

andy1968

Registered User.
Local time
Yesterday, 16:45
Joined
May 9, 2018
Messages
131
New similar issue.



This INSERT INTO is not working.



The problem seems to be with the Note field; if I change Note to a different field in the tblSubmittalNotes the sql works just fine.


Code:
strSql = "INSERT INTO [tblSubmittalNotes] ( SerialNumber, Note) " & _
                '    "SELECT " & lngID & " As SerialNumber, Note " & _
                  '   "FROM [tblSubmittalNotes] WHERE SerialNumber = " & ingOldID & ";"


 DBEngine(0)(0).Execute strSql, dbFailOnError


The Note field is a LongText
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:45
Joined
Oct 29, 2018
Messages
21,467
New similar issue.

This INSERT INTO is not working.

The problem seems to be with the Note field; if I change Note to a different field in the tblSubmittalNotes the sql works just fine.
Hi. Just curious, why are you "duplicating" the Notes in the same table? What error message were you getting with the above SQL statement?
 

andy1968

Registered User.
Local time
Yesterday, 16:45
Joined
May 9, 2018
Messages
131
Long Text.


Yes, duplicating into the same table.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:45
Joined
Oct 29, 2018
Messages
21,467
Long Text.

Yes, duplicating into the same table.
Hi. Sorry, I noticed that when I reread your post, so I updated my post and asked a different question.
 

andy1968

Registered User.
Local time
Yesterday, 16:45
Joined
May 9, 2018
Messages
131
Error 3134 (Syntax error in INSERT INTO statement.) in procedure



I'm adding a new parent record, and want to duplicate the notes to the new parent.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:45
Joined
Oct 29, 2018
Messages
21,467
Error 3134 (Syntax error in INSERT INTO statement.) in procedure

I'm adding a new parent record, and want to duplicate the notes to the new parent.
Okay, try to do a Debug.Print and then copy and paste the resulting SQL statement in the Query Designer, so you can see where the problem is.
 

andy1968

Registered User.
Local time
Yesterday, 16:45
Joined
May 9, 2018
Messages
131
Great.

Changed the sql as follow



Code:
strSql = "INSERT INTO [tblSubmittalNotes] ( SerialNumber, [Note]) " & _
                   "SELECT " & lngID & " As SerialNumber, Note " & _
                  "FROM [tblSubmittalNotes] WHERE SerialNumber = " & ingOldID & ";"


Working great.


Thanks for the tip.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:45
Joined
Oct 29, 2018
Messages
21,467
Great.

Changed the sql as follow

Code:
strSql = "INSERT INTO [tblSubmittalNotes] ( SerialNumber, [Note]) " & _
                   "SELECT " & lngID & " As SerialNumber, Note " & _
                  "FROM [tblSubmittalNotes] WHERE SerialNumber = " & ingOldID & ";"
Working great.

Thanks for the tip.
Congratulations! Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Top Bottom