I need to know if there is any way to take the data from an existing record and create a new record with the exact same data. The only info that would change is the primary key which is an autonumber field.<br><br>
yes, do you want to put it into a new table or just a new record in the same table? <p>Brian Famous<br><a href=mailto:bfamous@ncdoi.net>bfamous@ncdoi.net</a><br><a href= > </a><br>
This works:<br><br>Dim db As DAO.Database<br>Dim rst As DAO.Recordset<br>Dim fld As DAO.Field<br>Dim myarray() As String<br>Dim i As Integer<br><br>Set db = CurrentDb<br>Set rst = db.OpenRecordset("yourrecordsourcetableorquery"<br><br>For Each fld In rst.Fields<br> ReDim Preserve myarray(i)<br> myarray(i) = fld.Value<br> i = i + 1<br>Next<br>i = 0<br>rst.AddNew<br>For Each fld In rst.Fields<br> rst.Fields(i) = myarray(i)<br> i = i + 1<br>Next<br>'right here put code to set your primary field to<br>'something via a formula or input box or something.<br><br>rst.Update<br>Me.Requery<br>
Since you are using an autonumber field for the primary key then as you loop through the fields test to see if it is the primary key field and then just don't touch it with the code. Disregard my 2 commented lines in the previous post since you are autonumbering.
Ok I see how this could work and I'll try it but before I do, one question. The recordset that I open it should be a query that selects only the record I want "copied" yes?<br>
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.