Results 1 to 4 of 4
  1. #1
    Joakim N is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    Oct 2016
    Posts
    79

    Copy and Paste a Record in a subform

    Hi,
    If I want to copy and paste a record in a Form, I use following code:



    Code:
    Private Sub cmdDuplicate_Click()
        DoCmd.RunCommand acCmdSelectRecord
        DoCmd.RunCommand acCmdCopy
        DoCmd.RunCommand acCmdPasteAppend
    End Sub
    How can I write the code to copy and paste a record in a Subform? The button cmdDuplicate is located in the Main Form.

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Which record of the subform is to be duplicated.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Joakim N is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    Oct 2016
    Posts
    79
    Actually all of them.

    I believe I can use:
    Code:
    ...
    DoCmd.RunCommand acCmdSelectAllRecords
    ...
    But how do I get DoCmd works on the subform? I found something like using:

    Code:
    Me.MySubform.SetFocus
    I haven't tied it yet. I'll do that tomorrow. Maybe you can tell me if I am on the right track.


    to get DoCmd to work on the sub form.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    subform references don't work that way; you have to drill down to the subform control, then reference the subform via .Form, and I don't think you can use Me either.
    Try Forms("MainFormName").Controls("subformControlName ").Form where subformControlName is not the name of the subform, but its control.
    This is one reason why it is good to not always settle for the names that Access form wizards create.
    So it might be [Forms]![Main form name]![subform control name].[Form]![control name on subform].SetFocus, to set focus to a subform control, for example.
    EDIT
    to reference a control on a subform I use
    [Forms]![Main form name]![subform control name].[Form]![control name on subform]
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 3
    Last Post: 03-09-2013, 10:39 AM
  2. Copy-paste every other record into bew table
    By BorisGomel in forum Access
    Replies: 5
    Last Post: 02-09-2012, 03:52 PM
  3. Opening sibform at the last record.
    By BorisGomel in forum Access
    Replies: 1
    Last Post: 11-09-2011, 11:50 AM
  4. Cut/Paste Feild values to new record
    By nickiwinki in forum Access
    Replies: 14
    Last Post: 10-25-2011, 11:56 AM
  5. Copy/paste to new record.
    By xbox1513 in forum Forms
    Replies: 1
    Last Post: 02-23-2011, 04:52 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