By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,481 Members | 1,199 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,481 IT Pros & Developers. It's quick & easy.

How to Copy Records of a Form to Another?

P: 29
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
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdOrdered_Click()
  2. DoCmd.RunSQL "UPDATE Sales SET Sales.Action = 'Ordered'" & _
  3. "WHERE (Sales.Action)= 'On-Order' AND (Sales.[Transaction Type])= 'Sold Re-Order' and (Sales.Barcode_Of_Goods)='" & Me.Barcode_Goods & "'"
  4.  
  5. Me.Barcode_Goods.SetFocus
  6. Me.Barcode_Goods.SelStart = 0
  7. Me.Barcode_Goods.SelLength = Len(Me.Barcode_Goods.Text)
  8. RunCommand acCmdCopy
  9.  
  10. DoCmd.OpenForm "New Stock"
  11. RunCommand acCmdPaste
  12.  
  13.  
  14. Me.Requery
  15. End Sub
Apr 5 '14 #1
Share this Question
Share on Google+
6 Replies


Expert 100+
P: 1,240
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
Apr 5 '14 #2

P: 29
Sorry I haven't explain myself well. Infact its only the following code which need to be modify:
Expand|Select|Wrap|Line Numbers
  1.  Me.Barcode_Goods.SetFocus
  2. Me.Barcode_Goods.SelStart = 0
  3. Me.Barcode_Goods.SelLength = Len(Me.Barcode_Goods.Text)
  4. RunCommand acCmdCopy
  5.  
  6. DoCmd.OpenForm "New Stock"
  7. RunCommand acCmdPaste
Apr 6 '14 #3

P: 29
I need to copy the field "Barcode_Goods" 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
Apr 6 '14 #4

Expert 100+
P: 1,240
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
Expand|Select|Wrap|Line Numbers
  1. Forms![New Stock]!Barcode_Goods.Text=me.Barcode_Goods.Text
  2.  
Forget the copy/paste, just do assignments from one form/field to the other.

Jim
Apr 6 '14 #5

P: 29
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
Apr 6 '14 #6

Expert 100+
P: 1,240
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.
Expand|Select|Wrap|Line Numbers
  1. Forms![New Stock]!Barcode_Goods.Text=me.Barcode_Goods.Text
  2. Forms![New Stock]!Sold.Text=me.Barcode_Actual_In_Hand.Text
  3. Forms![New Stock]!In_Hand.Text=me.To_Order.Text
Jim
Apr 6 '14 #7

Post your reply

Sign in to post your reply or Sign up for a free account.