Syntax error on insert statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rcsmith0712
    New Member
    • Jun 2020
    • 5

    #1

    Syntax error on insert statement

    Hi Folks. I have a simple insert statement only four fields. The last field "Table" is the problem child. IF I take it out and the associated value "Me.txtTemp Tab" the insert statement works. Image of code also attached. Any assistance would be greatly appreciated. Thank you in advance...
    Code:
    DoCmd.RunSQL "INSERT INTO tblScrBldSched " & _
    "( OrderNo, Tech, SchedDate, Table )" & _
    "VALUES ('" & Me.cmbSTBT1A.Column(0) & "' ," & _
    " '" & Me.cmbScrTechT1A.Column(0) & "' ," & _
    " '" & Me.txtSchedDate & "' ," & _
    " '" & Me.txtTempTab & "' );"
    Attached Files
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    First, try a couple of minor adjustments:
    Code:
    DoCmd.RunSQL "INSERT INTO tblScrBldSched " & _
                 "([OrderNo], [Tech], [SchedDate], [Table])" & _
                 " VALUES ('" & Me.cmbSTBT1A.Column(0) & "' ," & _
                 "'" & Me.cmbScrTechT1A.Column(0) & "' ," & _
                 "'" & Me.txtSchedDate & "' ," & _
                 "'" & Me.txtTempTab & "');"

    Comment

    • rcsmith0712
      New Member
      • Jun 2020
      • 5

      #3
      Thanks ADezii. That worked! Though I'm not sure why the brackets are needed in this case. Can you help me understand why?

      Comment

      • cactusdata
        Recognized Expert New Member
        • Aug 2007
        • 223

        #4
        The brackets are only needed for reserved words and names with spaces or weird characters.
        Also, a date value should be inserted as a string expression for the date value, not as text, thus:

        Code:
        DoCmd.RunSQL "INSERT INTO tblScrBldSched " & _
        "( OrderNo, Tech, SchedDate, [Table] ) " & _
        "VALUES ('" & Me.cmbSTBT1A.Column(0) & "', " & _
        "'" & Me.cmbScrTechT1A.Column(0) & "', " & _
        "#" & Format(Me!txtSchedDate.Value, "yyyy\/mm\/dd") & "#, " & _
        "'" & Me.txtTempTab & "');"

        Comment

        Working...