Results 1 to 5 of 5
  1. #1
    stildawn is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Oct 2013
    Posts
    185

    Runtime 3131 Error On Insert Into + Union

    Hi All

    I have the below which is throwing a 3131 - Syntax error in FROM clause:



    Code:
    CurrentDb.Execute "INSERT INTO FRT_Table SELECT dbo_Archive_FRT_Table.* FROM dbo_Archive_FRT_Table UNION SELECT Current_FRT_Table.* FROM Current_FRT_Table;", dbFailOnError
    It is simply combining an archive data table with the current data table, into a combined working data table, but I can't seem to get it to work. (all tables are literally a copy and paste structure wise from each other)

    Any ideas?
    Last edited by stildawn; 08-09-2021 at 10:34 PM.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Save the UNION SQL as a query object then reference that object in the Execute.

    Or

    run two INSERT actions
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    stildawn is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Oct 2013
    Posts
    185
    Quote Originally Posted by June7 View Post
    Save the UNION SQL as a query object then reference that object in the Execute.
    What would the code be for that? I know how to create the UNION query object, I just have never combined a execute action with a query object before.

    Quote Originally Posted by June7 View Post
    run two INSERT actions
    This I assume would be as per below:

    Code:
    CurrentDb.Execute "INSERT INTO FRT_Table SELECT dbo_Archive_FRT_Table.* FROM dbo_Archive_FRT_Table;", dbFailOnError
    CurrentDb.Execute "INSERT INTO FRT_Table SELECT Current_FRT_Table.* FROM Current_FRT_Table;", dbFailOnError

    Which of the two options would be the most efficient in processing time? Note the dbo table is up in our Azure SQL server, the other two are local within access, they are also quite large the dbo is around 9000 records, and the current one is sitting at 7500 records and both obviously will only get bigger.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Reference query object same as table.

    Some say saved query objects are faster.

    Guess you will have to test.

    9000 records is really quite small.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    stildawn is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Oct 2013
    Posts
    185
    Thanks, I have made the query objects version and it seems to be working.

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

Similar Threads

  1. SYNTAX ERROR 3131 - Adding information to table via form
    By programmingnewby in forum Access
    Replies: 4
    Last Post: 07-11-2019, 10:22 AM
  2. Replies: 9
    Last Post: 01-24-2018, 06:41 PM
  3. insert getting runtime error 3134
    By vicsaccess in forum Programming
    Replies: 5
    Last Post: 12-06-2015, 09:50 PM
  4. Replies: 13
    Last Post: 05-30-2014, 04:07 PM
  5. Insert Into Union query
    By Deutz in forum Queries
    Replies: 4
    Last Post: 08-18-2011, 10:28 PM

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