INSERT INTO statement, what is wrong with my syntax? :(

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • spudpeel
    New Member
    • Jul 2007
    • 8

    INSERT INTO statement, what is wrong with my syntax? :(

    Hi,
    I have to insert 10 pieces of data (8 from text or combo boxes, and 2 from variables), into my table. I'm sure Im getting the quotes wrong somewhere, but whatever I try I just cant see anything wrong.
    I'd really appreciate it If someone could help me with this, Its driving me crazy!
    The Code is below:
    Code:
    DoCmd.RunSQL "INSERT INTO tblDocs ([Doc Name],[Doc Code],[Description],[DepC],[Version],[Master],[Authorised],[Physical Location],[Publish Date],[Current]) Values (" '" & Me.combo18 & "','" & Me.[Doc Code] & "','" & Me.Description & "','" & Me.combo16 & "','" & Me.text20 & "','" & Newlink & "','" & Me.NewLinkPdf & "','" & Me.hardcopy& "','" & Me.[Publish Date] & "','" & "Yes");"
    Many thanks
    Sam
    Last edited by JKing; Aug 22 '07, 12:41 PM. Reason: [CODE] Tags
  • istya
    New Member
    • Aug 2007
    • 35

    #2
    Originally posted by spudpeel
    Hi,
    I have to insert 10 pieces of data (8 from text or combo boxes, and 2 from variables), into my table. I'm sure Im getting the quotes wrong somewhere, but whatever I try I just cant see anything wrong.
    I'd really appreciate it If someone could help me with this, Its driving me crazy!
    The Code is below:

    DoCmd.RunSQL "INSERT INTO tblDocs ([Doc Name],[Doc Code],[Description],[DepC],[Version],[Master],[Authorised],[Physical Location],[Publish Date],[Current]) Values (" '" & Me.combo18 & "','" & Me.[Doc Code] & "','" & Me.Description & "','" & Me.combo16 & "','" & Me.text20 & "','" & Newlink & "','" & Me.NewLinkPdf & "','" & Me.hardcopy& "','" & Me.[Publish Date] & "','" & "Yes");"

    Many thanks
    Sam
    You only need the quotes in the SQL statement aroung the text values, the others don't require quotes. Are all your fields text? Have you tried viewing the completed string before you run the SQL?

    Comment

    • spudpeel
      New Member
      • Jul 2007
      • 8

      #3
      Does text values include the commas between the items?

      Comment

      • istya
        New Member
        • Aug 2007
        • 35

        #4
        Originally posted by spudpeel
        Does text values include the commas between the items?
        I mean are Me.combo18, Me.[Doc Code], Me.Description, Me.combo16, Me.text20, Newlink, Me.NewLinkPdf, Me.hardcopy and Me.[Publish Date] text values or are some numbers? Also I notice that you have a date - is that in a date format or not? The datatype that needs quotes in a SQL statement is text, as far as I am aware, number and dates don't need the quotes.

        Does that explain what I mean better?

        Comment

        • JKing
          Recognized Expert Top Contributor
          • Jun 2007
          • 1206

          #5
          Assuming they are all text fields. Try this:

          [code=vb]
          DoCmd.RunSQL "INSERT INTO tblDocs ([Doc Name],[Doc Code],[Description],[DepC],[Version],[Master],[Authorised],[Physical Location],[Publish Date],[Current]) Values ('" & Me.combo18 & "','" & Me.[Doc Code] & "','" & Me.Description & "','" & Me.combo16 & "','" & Me.text20 & "','" & Newlink & "','" & Me.NewLinkPdf & "','" & Me.hardcopy & "','" & Me.[Publish Date] & "', Yes);"
          [/code]

          Comment

          • spudpeel
            New Member
            • Jul 2007
            • 8

            #6
            Huge thanks, that works perfectly!

            To itsya - you were clear, i just didnt know if the commas were quoted.

            Thanks very much!

            Comment

            Working...