Results 1 to 3 of 3
  1. #1
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496

    copy records within the same table

    my goal is to filter a table and then make a copy of all of those records (into that same table) with a change to 1 field (only).
    that is to say, if the table had 5 records (a, a, b, c, d), i want to filter for 'a', and then copy those 2 records to 'e' (always a new designation, never b, c, or d..) so that the resulting set of records would be: a, a, b, c, d, e, e) and all of the information in the 'a' and 'e' records would be the same except for the identifying field ('a' or 'e')...

    i've got this code (which isn't working) and suspect that i'm going about it with the completely wrong aproach...
    any thoughts would be greatly appreciated in advance)

    --------------------------------------
    Set Db = CurrentDb()
    Set rstSourceCuts = Db.OpenRecordset("SELECT * " & _
    "FROM tbeAdditionalPages " & _
    "WHERE tbeAdditionalPages.type = '" & vSourceType & "';")
    Set rstTargetCuts = Db.OpenRecordset("SELECT * " & _
    "FROM tbeAdditionalPages " & "';")

    If rstSourceCuts.RecordCount > 0 Then
    rstSourceCuts.MoveLast

    Do Until rstSourceCuts.BOF
    rstTargetCuts.AddNew
    rstTargetCuts.Type = vType 'vType is the new value, determined previously in the sub, for the field 'type', which is the field whose value does change; all the other field values remain the same.

    For Each fld In rstTargetCuts.Fields
    strFieldName = fld.Name



    If fld.Name <> "Type" Then
    rstTargetCuts.Fields(strFieldName) = fld.Value
    rstTargetCuts.Update
    End If

    Next fld

    rstSourceCuts.MovePrevious
    Loop

    End If

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Why isn't it working - error message, wrong results, no results? Have you step debugged? You can probably do this with a INSERT INTO SELECT sql action and would not need the recordset. Check this for starters http://msdn.microsoft.com/en-us/libr...ffice.12).aspx
    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
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    "insert into".... elegantly simple
    (as a good friend of mine, and many of you in AF.net, have said: "check the obvious first !" )

    thanks

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

Similar Threads

  1. Replies: 9
    Last Post: 12-19-2011, 06:30 PM
  2. Replies: 1
    Last Post: 12-18-2011, 01:52 AM
  3. Replies: 3
    Last Post: 10-24-2011, 11:42 AM
  4. Creating a copy of records between databases
    By andrewosborne in forum Import/Export Data
    Replies: 4
    Last Post: 09-22-2011, 12:56 AM
  5. Replies: 2
    Last Post: 04-02-2010, 07:42 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