Results 1 to 7 of 7
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    Can't find a simple syntax error

    Access complains there's a syntax error but I've not been able to discover where it might be. I've tried the SELECT with and without parenthesis but didn't seem to fix anything. Any ideas?



    Code:
    DoCmd.RunSQL "CREATE TABLE tblOneLabel AS (SELECT BoxID, AreaName FROM tblBoxLabels WHERE [RecID] = 1);"

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You're trying to make a new table? Try

    SELECT BoxID, AreaName
    INTO tblOneLabel
    FROM tblBoxLabels WHERE [RecID] = 1
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Your suggestion worked perfectly. The sub where the statement below executes is passed "SeedID".

    Code:
    DoCmd.RunSQL "SELECT * INTO tblOneLabel FROM tblBoxLabels WHERE [RecID] = " & SeedID
    Is there a way to get RunSQL to execute quietly? Two messages display: 1 that table "tblOneLabel" is being replaced and 2 that a record is being added.

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,972
    There are two methods
    You can add the line DoCmd.SetWarnings False before running the code and then DoCmd.SetWarnings True afterwards
    Doing that suppresses all messages including error messages

    A better method is to use CurrntDb.Execute instead of DoCmd.RunSQL.
    That suppresses unwanted messages except for errors
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

  6. #6
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Thanks Colin. As soon as I corrected the spelling error all worked as desired.

    What struck me as a bit humorous is the fact that I don't recall EVER having used DoCmd.RunSQL. I think it might have occurred resulting from a Cut/Paste of an example somewhere.

    Thanks again,
    Bill

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Thanks Paul, lesson learned.
    Bill

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

Similar Threads

  1. Simple Syntax Error on SQL
    By dccjr3927 in forum Programming
    Replies: 10
    Last Post: 04-22-2019, 11:39 AM
  2. Replies: 2
    Last Post: 05-09-2015, 01:34 PM
  3. Can't find a SQL syntax error
    By GraeagleBill in forum Programming
    Replies: 3
    Last Post: 07-21-2013, 06:09 PM
  4. Can't find the syntax error in this SQL
    By FelicianoRa@coned.com in forum Programming
    Replies: 1
    Last Post: 02-14-2013, 09:04 AM
  5. simple syntax ?
    By markjkubicki in forum Queries
    Replies: 2
    Last Post: 10-09-2012, 10:31 AM

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