Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I Clone record?

Status
Not open for further replies.

OrlandoG7

Technical User
Jan 1, 2002
33
US
I need to duplicate some fields (not all fields) in my form and send them to a new record in the same form. I've read several postings about cloning records but don't understand how to implement it.

Thanks,
Orlando
 
You need to be a bit more specific on what you mean by

"duplicate some fields (not all fields) in my form and send them to a new record in the same form"

would this be during data entry and you just want to carry the values from the previous form over to the next

or would you be looking at a saved record and want to duplicate some of the fields onto a new record
 
I would you be looking at a saved record and want to duplicate some of the fields onto a new record.
 
OrlandoG7, you posted this in at least 3 different places. Your're confusing me. Because I thought I answered your question, only to find out later that my response wasn't there, then found out my response was posted on a different thread.
 
Sorry FancyPrairie for confusion. I was hoping to get a vba or non-vba solution so I posted question on different forums.

You suggested the method below. I can't get it to work properly. After below code is executed, a new record is created but field values are not transfered. does paste append have any type of restrictions on locked or calculated form fields?

'Select record
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
'copy record
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70

DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append

' Then delete the fields you don't want
Me!Name = ""
Me!Address = ""

and so on
 
fancyprarie offers a very good solution and I think you should look into it closer. It should be simple to implement

Since you are looking for alternatives I will offer another
'assumes key is an autonumber

dim rst as dao.recordset
Docmd.runsql "insert into tblname (fld1,fld2,fld3...etc) values(forms!formname!fld1name, forms!formname!fld2name,forms!formname!fld3name...etc)
me.refresh
set rst = me.recordsetclone
rst.findfirst "key = " & dMax("key","tblname)
me.bookmark = rst.bookmark
set rst = nothing

this will need serious debugging but someting along these lines should do it. But as you can see it is not really better then the other solution offered




 
I hate to take credit for someone else's work. The solution above was not mine. What I suggested in one of the other posts was to use the default value property. For example, suppose the user enters data into record 1, after the record has been updated, then set the defaultvalue property of the fields you want to their current value. Then, when the user adds a new record, the fields will already be populated. The following code assumes that if the DefaultValue has not yet been set, this code will set it.
Code:
Sub Form_AfterUpdate()

    if (txtCloneField1.DefaultValue = vbNullString) then
        txtCloneField1.DefaultValue = """" & txtCloneField1.Value & """"

        txtCloneFieldx.DefaultValue = ....
    End if

End Sub
 
Thanks for both of the good sugestions. It gives me a great starting point.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top