Results 1 to 4 of 4
  1. #1
    DWolff is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Location
    Coral Springs, FL
    Posts
    2

    Append Records from one table to another from a DoCmd.RunSQL.


    I'd like to copy selected records from one Access table to another. I know how to create an Append Query, but this won't meet my needs, as I actually want to run 20 successive queries, and would prefer to do it with a single button rather than writing (and storing) 20 queries.

    It seems that this should be easy, but I cannot seem to get the right syntax. I started with a normal SQL Insert as follows:

    Code:
    INSERT INTO TempFixCase17 ( ID, OrigLen, CaseNumber, NewCase, State, County, ann_fname, ann_lname, FilingDate, DocType )
    SELECT TempFixCases.ID, TempFixCases.OrigLen, TempFixCases.CaseNumber, TempFixCases.NewCase, TempFixCases.State, TempFixCases.County, TempFixCases.ann_fname, TempFixCases.ann_lname, TempFixCases.FilingDate, TempFixCases.DocType
    FROM TempFixCases
    WHERE (((TempFixCases.LIST)="List017"));[

    Not even close. When that didn't work, I found something here that told me to try:

    Code:
    DoCmd.RunSQL "Insert into [TempFixCase17] (Select from [TempFixCases] where [TempFixCases].
    [List]="List017")
    That didn't work either.

    Can someone tell me the magic?

    (P.S. This is my first time on the forum. Only after I posted did I notice the "FORMS" forum where, perhaps, this question belongs. My apologies)

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    Why not working - error message, wrong results, nothing happens?

    Why do you need to copy records as opposed to just filtering?

    The queries look fine except for the VBA approach. Use apostrophes around List017 instead of quotes and then final quote at the end. Also not sure the parens are needed, might cause issue. I prefer CurrentDb.Execute method to run sql actions:

    CurrentDb.Execute "INSERT INTO TempFixCase17 SELECT FROM TempFixCases WHERE List='List017'"
    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
    DWolff is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Location
    Coral Springs, FL
    Posts
    2

    Cool

    Thanks so much, June7. I appreciate your help VERY much.

    First, to answer your question (trying to keep it short). We use SharePoint, and I update 20 lists regularly. I run a query in Access to determine all the data that needs updating by list. I use SSIS to link directly from a table in Access to each SharePoint List (1 to 1 relation between access table and SharePoint list). For this reason, I need to parse all the data from the query into 20 separate Access tables to update each list

    I was unaware of the CurrentDb.Execute function, which I much prefer. Unfortunately, when I tried it (exactly as you typed), it gave a a run-time error 3134 indicating an error in the INSERT INTO statement. I then realized you left out the * in the select statement ". . .SELECT * FROM TempFixCases WHERE List='List017'". It worked GREAT.


    Quote Originally Posted by June7 View Post
    Why not working - error message, wrong results, nothing happens?

    Why do you need to copy records as opposed to just filtering?

    The queries look fine except for the VBA approach. Use apostrophes around List017 instead of quotes and then final quote at the end. Also not sure the parens are needed, might cause issue. I prefer CurrentDb.Execute method to run sql actions:

    CurrentDb.Execute "INSERT INTO TempFixCase17 SELECT FROM TempFixCases WHERE List='List017'"

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    Ooops! And I was copying from your post as i typed, didn't hit me missing the fields (or the *) in the SELECT.

    Glad that works now. So this issue is resolved?
    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.

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

Similar Threads

  1. Replies: 2
    Last Post: 05-16-2012, 07:46 AM
  2. my first DoCmd.RunSQL
    By broecher in forum Programming
    Replies: 4
    Last Post: 11-05-2010, 09:35 PM
  3. docmd.runsql update
    By Mitch_Aus in forum Programming
    Replies: 2
    Last Post: 10-05-2010, 09:45 AM
  4. Problem with DoCmd.RunSQL
    By Peter01 in forum Programming
    Replies: 2
    Last Post: 09-10-2009, 07:11 PM
  5. docmd.runsql not working
    By Rameez in forum Programming
    Replies: 3
    Last Post: 08-07-2009, 10:07 AM

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