duplicate data

kim40

Registered User.
Local time
Today, 08:49
Joined
Aug 24, 2012
Messages
30
I have this code but it does not duplicate the record, how do i get it to duplicate a record?

Set rs = db.OpenRecordset("SELECT * FROM CustomerOrder WHERE(Product = """ & Me.Product & """)")
If rs.EOF Then
With rs
.AddNew
.Fields("Product") = Me.Product.Value
.Fields("Guilders") = Me.Guilders.Value
.Update
.Close
End With
Else
MsgBox "ok"
End If
Thanks
 
You are trying to perform this at EOF - there is no current record to copy.

Try rs.movelast and then rs.addnew
 
I Am getting a compilation error when I add rs.movelast and then rs.addnew I get a compilation error
 
Can you confirm whether you are (a) trying to duplicate the last record of the recordset or (b) trying to add a new record to the recordset with values set by a form (i.e. product & guilders).

Thanks
 
I am trying to add a record to a record set(e.g. if I have eggs i need to add it to multiple customers.
I want to add 1 item to multiple customers

Thanks
 
The following code should allow you to add a new record to the recordset based on the values held in your form. Am still not clear on what you need to duplicate, but hopefully this works for you.

Dim rs As Recordset
Dim qdf As DAO.QueryDef
Set qdf = CurrentDb.CreateQueryDef("")
qdf.Sql = "SELECT * FROM CustomerOrder WHERE(Product = """ & Me.Product & """)"

Set rs = qdf.OpenRecordset



With rs
.AddNew
.Fields("Product") = Me.Product.Value
.Fields("Guilders") = Me.Guilders.Value
.Update
.Close
End With
 
thanks for the help.I have an inventory table with about a 1000 grocery items. I have a customers table. I have a form that I can search for the items. When I find the item I want to click on it and add to the customer table. This I have done but what i need to do is to be able to click and it adds wether it is in the table or not. I have added For i = 1 to
.AddNew
.Fields("Product") = Me.Product.Value
.Fields("Price") = Me.Price.Value
.Update
Next i
but it adds the number of times at once
 

Users who are viewing this thread

Back
Top Bottom