Syntax (Missing Operator) in Query Expr ....

  • Thread starter Thread starter TeeSee
  • Start date Start date
T

TeeSee

When I run the following code I get the error message "Syntax Error
(Missing Operator in Query Expression 'C:\MyDocuments ....... \My.Doc'

Private Sub txtType_AfterUpdate()
Dim db As DAO.Database
Dim strSQL As String

Set db = DBEngine(0)(0)


strSQL = "INSERT into tblDataPaths (DataPathID, txtCode,
txtSavedData, txtDataType)"
strSQL = strSQL & "VALUES (" & DataPathID & "," & txtCode & "," &
txtPath & "," & txtType & ");"
Debug.Print strSQL
db.Execute strSQL, dbFailOnError
Set db = Nothing
Me.Requery
End Sub

When I copy the strSQL into the SQL window and run it I get the same
error message and the cursor blinks on the colon after the capital C
and I can't figure out why. Can anyone please suggest a solution.

Thanks as always
 
TeeSee said:
When I run the following code I get the error message "Syntax Error
(Missing Operator in Query Expression 'C:\MyDocuments ....... \My.Doc'

Private Sub txtType_AfterUpdate()
Dim db As DAO.Database
Dim strSQL As String

Set db = DBEngine(0)(0)


strSQL = "INSERT into tblDataPaths (DataPathID, txtCode,
txtSavedData, txtDataType)"
strSQL = strSQL & "VALUES (" & DataPathID & "," & txtCode & "," &
txtPath & "," & txtType & ");"
Debug.Print strSQL
db.Execute strSQL, dbFailOnError
Set db = Nothing
Me.Requery
End Sub

When I copy the strSQL into the SQL window and run it I get the same
error message and the cursor blinks on the colon after the capital C


The SQL statement resulting from concatenating the path into
the SQL string must be enclosed in quotes:

strSQL = "INSERT into tblDataPaths (DataPathID, txtCode, " _
& "txtSavedData, txtDataType)" _
& "VALUES(""" & DataPathID & """," & txtCode _
& ",""" & txtPath & """," & txtType & ")"
 
TeeSee said:
When I run the following code I get the error message "Syntax Error
(Missing Operator in Query Expression 'C:\MyDocuments ....... \My.Doc'
Private Sub txtType_AfterUpdate()
Dim db As DAO.Database
   Dim strSQL As String
   Set db = DBEngine(0)(0)
   strSQL = "INSERT into tblDataPaths (DataPathID, txtCode,
txtSavedData, txtDataType)"
   strSQL = strSQL & "VALUES (" & DataPathID & "," & txtCode & "," &
txtPath & "," & txtType & ");"
 Debug.Print strSQL
   db.Execute strSQL, dbFailOnError
   Set db = Nothing
   Me.Requery
End Sub
When I copy the strSQL into the SQL window and run it I get the same
error message and the cursor blinks on the colon after the capital C

The SQL statement resulting from concatenating the path into
the SQL string must be enclosed in quotes:

strSQL = "INSERT into tblDataPaths (DataPathID, txtCode, " _
                        & "txtSavedData, txtDataType)" _
                        & "VALUES(""" & DataPathID & """," & txtCode _
                        & ",""" & txtPath & ""","& txtType & ")"

--
Marsh
MVP [MS Access]- Hide quoted text -

- Show quoted text -

Hi Marsh ... Thanks for your response. I have to freely admit that I
find it difficult to follow what actually goes on with all these """"
's. I copied your code and still received similar errors. Then a wee
light went on and I believe I realized what I shd have been trying to
achieve. The following code now works and you will see that I added
several more quotes in order for it to work (Which it does). This WAS
a bit of trial & error.
strSQL = "INSERT into tblDataPaths (DataPathID, txtCode, " _
& "txtSavedData, txtDataType)" _
& "VALUES(""" & DataPathID & """,""" & txtCode
_
& """,""" & txtPath & """,""" & txtType &
""")"
INSERT into tblDataPaths (DataPathID, txtCode, txtSavedData,
txtDataType)VALUES("5",G10FR4,"C:\Documents and Settings\My Documents
\my.doc",2)
Above is the output from Debug.Print using your code while the
following is the output from the code with all the extra """" 's.
INSERT into tblDataPaths (DataPathID, txtCode, txtSavedData,
txtDataType)VALUES("5","G10FR4","C:\Documents and Settings\My Documents
\my.doc","2")
Would you please take a couple of minutes to explain what has happened
here. Have I achieved what I should have or have I taken another wrong
turn? Also if you couldexplain how the quotes are supposed to properly
work. Thanks again Marsh.
 
Back
Top