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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Duplicate only certain fields in a record

Status
Not open for further replies.

tyleri

Programmer
Jan 2, 2001
173
US
I have a form, and i used the "wizard" to set up a "duplicate record" button.

It duplicates all of the fields in the form.

Is there a way that I can set it so that it only duplicates 3 or 4 of the fields in the form?

Here is the wizard code:

Private Sub Command49_Click()
On Error GoTo Err_Command49_Click

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

Exit_Command49_Click:
Exit Sub

Err_Command49_Click:
MsgBox Err.Description
Resume Exit_Command49_Click

End Sub

Thanks
 
Without knowing the specifics of the record you should be able to with VBA code access the new record and clear out the fields that you don't want and then refresh the form with the newly partially duplicated record.

Immediately about the code provided you could do something like this:

dim db as database
dim rs as recordset
set db = currentdb
set rs = db.openrecordset("tblYourTable", dbOpenDynaset)
rs.movelast
rs.edit
rs("Field1") = null
rs("Field2") = null
etc, etc, etc. clearing out all fields
rs.update
rs.close
db.close
me.refresh

This is not exactly the right code but you should get the idea. You will have to identify the fields to clear out and substitute them for Field1, Field2, etc.

You could have actually just created a button to perform this function yourself and just performed a rs.addnew and updated the fields from the record on the form, saved it, and then requeried and refreshed the form.

If that is what youwant we can provide that also.

Bob Scriver
 
I couldn't seem to get that to work. I can revise the simplicity of my question:

When I click the "duplicate record" button and it creates a new record with all fields filled in, how do I make it so that 4 of the fields are blank?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top