Copy and pasting within a form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lrw0831
    New Member
    • Sep 2008
    • 18

    Copy and pasting within a form

    I have the main form where employees enter "issues". Some issues have fields that are the same. My fields are

    Issue ID (auto)
    Product
    Entered BY
    Issue Type
    Priority
    Request from
    Status
    Assigned to
    Model
    Description

    Is there a way to have a "Copy" button that would copy all of the information in the form, and then paste it into the same form but in a new record?

    Example...Say I have an issue that needs to be assigned to 2 different departments, I want to enter a new issue (we'll just say its issue 9) then have a copy button that would copy all of that information then open issue 10 and paste it in there.

    Thank you for any help in advanced.

    Lindsay
  • bluemoon9
    New Member
    • Oct 2008
    • 56

    #2
    Hi,
    create a command button (cmdCopy) on the form and paste this code onto the "On Click" event
    Code:
    DoCmd.RunCommand acCmdSelectRecord
      DoCmd.RunCommand acCmdCopy
      DoCmd.GoToRecord , , acNewRec
      DoCmd.RunCommand acCmdPaste
    Or you can use the access wizzard to create a "Duplicate Record" command. Here is the code from the wizzard:
    Code:
    Private Sub cmdCopy_Click()
    On Error GoTo Err_cmdCopy_Click
        DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
        DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
        DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append
    
    Exit_cmdCopy_Click:
        Exit Sub
    
    Err_cmdCopy_Click:
        MsgBox Err.Description
        Resume Exit_cmdCopy_Click
        
    End Sub
    hopes this'll help.
    bluemoon

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #3
      The former would be the recommended way. The wizard-created code is rubbish :(

      Comment

      • lrw0831
        New Member
        • Sep 2008
        • 18

        #4
        How would i code it so that it only copies a few of the fields, not all of them?

        SUpposed I just want Product, Entered BY, Issue Type, Priority, Request from, and Status to be copied and pasted onto the next issue.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32633

          #5
          That would be an entirely different issue.

          You would need to save your own copies of the data required, move to the rnext record, then update the relevant controls with the saved data.

          Comment

          • Stewart Ross
            Recognized Expert Moderator Specialist
            • Feb 2008
            • 2545

            #6
            Hi. I suggest you consider something different which may help with your requirement to 'copy' values from one record to the next - don't copy them, set the default value for the controls concerned instead.

            How is this done? In the After Update event of each control whose value you want to carry forward simply enter the following event code, substituting the correct name of the control in each case:

            Code:
            Me![your control name].DefaultValue = "'" & Me![your control name] & "'"
            This will set the default value for the control concerned to whatever was last entered. The default value property is a string (regardless of the type of the underlying field), hence the use of single quotes on either side of the value of the control.

            I use this technique a lot when I want to carry forward field values from record to record. It's a lot easier and safer to set defaults than it is to copy values from one record to another. Using defaults there is then no question of accidentally creating new records at the wrong time, which is what will happen if you copy values into a blank record on a button press, say.

            -Stewart

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32633

              #7
              That's a good point Stewart. I fully endorse that.

              Comment

              Working...