Results 1 to 5 of 5
  1. #1
    Bcanfield83 is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    May 2018
    Posts
    81

    Question Run-time error 3134: Syntax error in INSERT INTO Statement


    Hi all,

    I'm attempting to insert data into a table through VBA.. but getting stumped on the error message in the subject line.
    Where I'm stumped is that the code executes just fine when I'm only trying to insert data into 2 fields.
    I temporarily updated the code to include a "Debug.Print strSQL" (instread of "DoCmd.RunSQL (strSQL)) so I could see what the actual SQL string was.

    This one works:

    Code:
    INSERT INTO tblDB_Users(USERID, ROLE) VALUES("jdoe", "read_only")
    This does not (produces the run-time error 3134):

    Code:
    INSERT INTO tblDB_Users(USERID, DATABASE, ROLE) VALUES("jdoe", "MyDB", "read_only")
    Is there something blindingly obvious I'm missing with the second iteration?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    21,773
    Not that I see; I assume all are text fields. Make sure the field is spelled correctly. You might also try bracketing it since it's a reserved word:

    [DATABASE]
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    isladogs's Avatar
    isladogs is offline Very idle programmer
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    4,806
    Database is a reserved word in Access and really should not be used as a field name
    Either change the field name or enclose it in [] brackets

    Code:
    INSERT INTO tblDB_Users(USERID, [DATABASE], ROLE) VALUES("jdoe", "MyDB", "read_only")
    Colin (Mendip Data Systems): Website, email
    Try again. Fail again. Fail better.
    A
    sking for help isn't giving up. Its refusing to give up.

  4. #4
    Bcanfield83 is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    May 2018
    Posts
    81
    Genius! It was indeed an issue with the field name being called "Database".. I changed it to "DB_Name" and viola - no error.
    Thank you both, I almost certaintly would've agonized over this for days before I figured that one out on my own.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    21,773
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Syntax Error on INSERT INTO statement
    By dccjr3927 in forum Programming
    Replies: 9
    Last Post: 01-08-2019, 04:03 PM
  2. CurrentDb.Execute INSERT syntax error 3134
    By GraeagleBill in forum Programming
    Replies: 8
    Last Post: 12-19-2015, 09:45 PM
  3. Replies: 1
    Last Post: 09-22-2014, 08:54 AM
  4. Replies: 3
    Last Post: 03-05-2013, 11:17 AM
  5. Syntax Error: Insert Into statement in VBA
    By Kimbertha in forum Programming
    Replies: 1
    Last Post: 07-24-2012, 05:02 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums - Senior Forums