Results 1 to 4 of 4
  1. #1
    jbickl is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2011
    Posts
    14

    Question Button to duplicate part of record

    Hello,



    My database's users want to use a button to create a new record and copy fields from the current record to hold over to the new record. I know how to do this for an entire record, but the users don't need to copy the entire thing. They need to copy particular fields and then input new information into the other fields. Any ideas?

    Thanks!

  2. #2
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    1. Save current record (If Me.Dirty=True Then Me.Dirty=False)

    2. Run an Append query (DoCmd.RunSQL) using the data on the form

    3. Get the PK of the record just added (DLookup("Max(ID)"........)

    4. Display this record

  3. #3
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    I have done this for specific fields in a record. Here is an example of the code used.

    Code:
    Private Sub copyrecordbutton_Click()
    On Error GoTo Err_copyrecordbutton_Click
    Dim pown As Variant
    Dim psource As Variant
    Dim pclient As Variant
    Dim ptax As Variant
    
    pown = txtcurrent1.Value
    psource = txtcurrent2.Value
    pclient = txtcurrent3.Value
    ptax = txtcurrent4.Value
    
    RunCommand acCmdRecordsGoToNew
    
    txtnew1.Value = pown
    txt2new.Value = psource
    txtnew3.Value = pclient
    txtnew4.Value = ptax
    
       
    Exit_copyrecordbutton_Click:
        Exit Sub
    
    Err_copyrecordbutton_Click:
        MsgBox Err.Description
        Resume Exit_copyrecordbutton_Click
        
    End Sub
    You will have to substiture your own field names and define your variants as needed. The code stores the values of the first record in a variant and then opens a new record and places the stored values in the new record in the same fields. Of course you will have to make sure that the new field names are the same as the old field names. I didn't in this example just so you could follow the code.

    Alan

  4. #4
    jbickl is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2011
    Posts
    14
    It works now. Thank you both for your help; it's much appreciated.

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

Similar Threads

  1. finding a record in a listbox part 2
    By mgwat69 in forum Programming
    Replies: 19
    Last Post: 11-14-2011, 01:31 PM
  2. Replies: 10
    Last Post: 04-19-2011, 03:38 PM
  3. Duplicate last record to next record in form
    By jdhaldane in forum Forms
    Replies: 4
    Last Post: 12-17-2010, 04:22 PM
  4. If duplicate record, go to original record
    By BigBear in forum Forms
    Replies: 2
    Last Post: 10-06-2010, 02:58 AM
  5. Duplicate command button
    By brettg in forum Database Design
    Replies: 1
    Last Post: 08-04-2008, 04:16 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