Results 1 to 7 of 7

Thread: Run Time 3134: Syntax Error in INSERT INTO statement

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2018
    Posts
    1

    Exclamation Run Time 3134: Syntax Error in INSERT INTO statement

    I really need help. I don't know what else to do I tried everything already and even restarted it but it keeps saying the damn thing. It's really important since i'm doing a database for a company. Please Help

    Code:

    Code:
     Private Sub cmdAdd_Click()
    
        Dim Query1 As String
        Query1 = "INSERT INTO FranklinOffshore([Description],[SWL Tonne],[Inches],[Model],[Safety Factor],[Date/LPO],[Manufacturer],[Opening Stocks],[January],[February],[March],[April],[May],[June],[July],[August],[September],[October],[November],[December,[Total Used],[Available Balance],[Minimum Stock], FOQ/FOI, Comments)" & _
        " VALUES ('" & Me!txtDescription _
        & ",'" & Me!txtSWLTonne.Value _
        & "','" & Me!txtInches.Value _
        & "','" & Me!txtModel.Value _
        & "','" & Me!txtSafetyFactor.Value _
        & "','" & Me!txtDatelpo.Value _
        & "','" & Me!txtManufacturer.Value _
        & "','" & Me!txtOpeningstocks.Value _
        & "','" & Me!txtJanuary.Value _
        & "','" & Me!txtFebruary.Value _
        & "','" & Me!txtMarch.Value _
        & "','" & Me!txtApril.Value _
        & "','" & Me!txtMay.Value _
        & "','" & Me!txtJune.Value _
        & "','" & Me!txtJuly.Value _
        & "','" & Me!txtAugust.Value _
        & "','" & Me!txtSeptember.Value _
        & "','" & Me!txtOctober.Value _
        & "','" & Me!txtNovember.Value _
        & "','" & Me!txtDecember.Value _
        & "','" & Me!txtTotalused.Value _
        & "','" & Me!txtAvailablebalance.Value _
        & "','" & Me!txtMinimumstock.Value _
        & "','" & Me!txtFoqfoi.Value & "','" & Me!txtComment.Value & "');"
        Debug.Print Query1
        DoCmd.RunSQL Query1
        
    End Sub
    It keeps saying the same thing, please help
    Name:  cd.PNG
Views: 769
Size:  4.9 KB

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Run Time 3134: Syntax Error in INSERT INTO statement

    The error message is telling you that there's an error in your INSERT statement and, as far as I can tell, you haven't even bothered to look at that statement. You certainly haven't bothered to show it to us. It should be obvious that you need to actually look at the SQL code and make sure it is what you expect it to be. If you do that then the issue should be obvious too.

  3. #3
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Run Time 3134: Syntax Error in INSERT INTO statement

    1) Three words: parameters, parameters, parameters
    2) Although in this case parameters wouldn't solve this issue specifically, it would at least help narrow down where the problem might be.
    3) Even once the problem is corrected (hint, look in your field names) there's still the issue with concatenating things together and sanitizing the data and potential SQL injection attacks.,
    4) Review this for an example of why SQL injections are bad.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Run Time 3134: Syntax Error in INSERT INTO statement

    Quote Originally Posted by techgnome View Post
    Although in this case parameters wouldn't solve this issue specifically
    There are at least two issues there and using parameters would solve one of them. You probably missed it because it's hard to see and it's hard to see because the code is hard to read, which is one of the very reasons to use parameters in the first place.

  5. #5
    Frenzied Member
    Join Date
    Jun 2014
    Posts
    1,084

    Re: Run Time 3134: Syntax Error in INSERT INTO statement

    kimaleah,
    the most important line in your code is:
    Debug.Print Query1
    is the result really what you expect it to be ?
    if you really want someone to help you:
    show the result
    do not put off till tomorrow what you can put off forever

  6. #6
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,834

    Re: Run Time 3134: Syntax Error in INSERT INTO statement

    Other comments aside this doesn't seem right:

    [Minimum Stock], FOQ/FOI, Comments)
    Please remember next time...elections matter!

  7. #7
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: Run Time 3134: Syntax Error in INSERT INTO statement

    This one too:
    [December,[Total Used],

    and this one:
    ('" & Me!txtDescription _
    & ",'"

    There's a single quote missing

    Agree with tg: Parameters
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width