How to Copy Records of a Form to Another?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jazee007
    New Member
    • May 2013
    • 29

    How to Copy Records of a Form to Another?

    Hi friends. I would like to copy certain records from a Form to another Form on 'Click'. The code works already but I don't know how to copy also other field. For the moment it copies only the first field
    Code:
    Private Sub cmdOrdered_Click()
    DoCmd.RunSQL "UPDATE Sales SET Sales.Action = 'Ordered'" & _
    "WHERE (Sales.Action)= 'On-Order' AND (Sales.[Transaction Type])= 'Sold Re-Order' and (Sales.Barcode_Of_Goods)='" & Me.Barcode_Goods & "'"
    
    Me.Barcode_Goods.SetFocus
    Me.Barcode_Goods.SelStart = 0
    Me.Barcode_Goods.SelLength = Len(Me.Barcode_Goods.Text)
    RunCommand acCmdCopy
    
    DoCmd.OpenForm "New Stock"
    RunCommand acCmdPaste
    
    
    Me.Requery
    End Sub
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1288

    #2
    jazee,
    Just follow Sales.Action = 'Ordered'" with a comma and the next field name and value.

    You can learn a ton about putting together SQL statements if you use the SQL view of the query editor. Use the query editor to make a query such as this one and the go into SQL view and see what the code looks like.

    Jim

    Comment

    • jazee007
      New Member
      • May 2013
      • 29

      #3
      Sorry I haven't explain myself well. Infact its only the following code which need to be modify:
      Code:
       Me.Barcode_Goods.SetFocus
      Me.Barcode_Goods.SelStart = 0
      Me.Barcode_Goods.SelLength = Len(Me.Barcode_Goods.Text)
      RunCommand acCmdCopy
       
      DoCmd.OpenForm "New Stock"
      RunCommand acCmdPaste

      Comment

      • jazee007
        New Member
        • May 2013
        • 29

        #4
        I need to copy the field "Barcode_Go ods" as well as other fields. But for the moment I've been able to copy only the field "Barcode_Goods" . Then I need to paste the records to the form "New Stock". Don't know how to do it. Thanks

        Comment

        • jimatqsi
          Moderator Top Contributor
          • Oct 2006
          • 1288

          #5
          jazee,
          I'm sorry, I believe the fault was mine. You did say from form to form and I zoomed in on the update statement. Completely wrong.

          It's a wonder to me that the code you have pastes anything. You open the form but don't put the focus on any particular object. I suppose Barcode_Goods is the first field on the form so you hit the jackpot with that one.

          You could try instead
          Code:
          Forms![New Stock]!Barcode_Goods.Text=me.Barcode_Goods.Text
          Forget the copy/paste, just do assignments from one form/field to the other.

          Jim
          Last edited by jimatqsi; Apr 6 '14, 11:51 AM. Reason: typo

          Comment

          • jazee007
            New Member
            • May 2013
            • 29

            #6
            Let me described the form. I got a form named A and the field I need to copy is as follows:
            Barcode_Goods
            Sold
            In_Hand

            Then When I clicked on a button, the records copied will be paste in the Form "New Stock" in the following fields:
            Goods
            Actual_In_Hand
            To_Order

            In summary:
            Barcode_Goods = Goods
            Sold = Actual_In_Hand
            In_Hand = To_Order

            Sorry for my english

            Comment

            • jimatqsi
              Moderator Top Contributor
              • Oct 2006
              • 1288

              #7
              So if you clicking a button on the form you call "A" you can refer to that form as ME. This would be the code to accomplish that.
              Code:
              Forms![New Stock]!Barcode_Goods.Text=me.Barcode_Goods.Text
              Forms![New Stock]!Sold.Text=me.Barcode_Actual_In_Hand.Text
              Forms![New Stock]!In_Hand.Text=me.To_Order.Text
              Jim

              Comment

              Working...