+ Reply to Thread
Results 1 to 4 of 4

Why do I get syntax error message on this INSERT INTO ?

  1. #1
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Why do I get syntax error message on this INSERT INTO ?

    I keep getting "-2147217900 [Microsoft][ODBC Excel Driver] Syntax error in INSERT INTO statement." on an INSERT INTO query

    Aside from the fact that I am not using parameters (like I should be), why am I suddenly getting this error message?


    What I have checked so far:
    • I googled the problem and thought that maybe the 'UserName' could be a reserved name so I altered it to 'UsrName' but it still occurs.
    • The workbook exists, as does the sheet, as does the field (header) names.
    • The workbook is not in use at time of writing. (I check with VBA before creating the connection string)
    • The record being inserted is after row 8 so it cant be a problem with the data types in the Excel table.
    • (update) Altered the 1.01 value to remove the ' prefix/suffix (so it wouldnt be written as a string). Still occurs
    • (update) Altered the table name from 'log' to 'MyLog'. Error still occurs.


    Could it be that one of the other field names be reserved?

    Could it be that the table name (log) is a reserved name? (Unlikely, changed to MyLog and still get error)

    Is it because I am specifying the primary key instead of letting it be assigned by auto-increment? (Doubtful as I have been using INSERT INTO with manually set PK into excel workbooks for a while now without any issues)

    Can anyone tell me what is causing this?


    My Query
    Please Login or Register  to view this content.
    My Connection String
    Please Login or Register  to view this content.
    Last edited by mc84excel; 03-22-2015 at 10:17 PM. Reason: updated to indicate other things tried
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

  2. #2
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Why do I get syntax error message on this INSERT INTO ?

    After trying many different solutions, I finally got it. After I changed the field name 'DateTime' to something else, the problem went away.

    "Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth."

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Why do I get syntax error message on this INSERT INTO ?

    If you want/need to use reserved words as field names, and I wouldn't recommend it, you can usually enclose them in [].

    INSERT INTO [log$] (ID, [DateTime], VerMMDB, UsrName, Activity) VALUES(11, 42086.52, 1.01, 'EXCEL', 'Upgraded BDF from v5 to v6')
    If posting code please use code tags, see here.

  4. #4
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Why do I get syntax error message on this INSERT INTO ?

    Quote Originally Posted by Norie View Post
    If you want/need to use reserved words as field names, and I wouldn't recommend it, you can usually enclose them in [].
    Thanks for providing the alternative option Norie. I had read that suggestion online but I mentally recoiled for some reason! (In the end, I went with changing the 'DateTime' to 'LogTime')

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Message box syntax error
    By batchjb69 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-17-2014, 05:43 PM
  2. Need help - Syntax error in insert into statement
    By rskfriends in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-20-2014, 03:46 AM
  3. insert into syntax error, sql not executing
    By sagar.rajula in forum Access Tables & Databases
    Replies: 1
    Last Post: 05-13-2013, 04:59 PM
  4. [SOLVED] Insert Into syntax error
    By LF83 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-25-2012, 09:48 PM
  5. syntax error in insert into statement in vba
    By iamsvs in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-12-2012, 03:35 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1