• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

MS Access - Duplicate record button, certain fields only?

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

medo145

Member
Joined
Jun 11, 2004
I have a form in access that I want people to be able to hit a button to copy certain fields to a new record and then fill out the rest

this is the current (default access) code that copies the record

Code:
Private Sub Duplicate_Project_Click()
On Error GoTo Err_Duplicate_Project_Click


    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdCopy
    DoCmd.RunCommand acCmdRecordsGoToNew
    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdPaste

Exit_Duplicate_Project_Click:
    Exit Sub

Err_Duplicate_Project_Click:
    MsgBox Err.Description
    Resume Exit_Duplicate_Project_Click
    
End Sub

Would the easiest way to accomplish this be, to clear the fields I don't want copied after the paste command? If so how?

Thanks
 
How do they select the record they are copying? Using the built-in navigation buttons (bottom of the screen arrows?)

The function you have basically copies out the whole record, duplicates it as a new record and displays it in the form. From there you can just do something like the following (this is inside your copy function):

Code:
    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdCopy
    DoCmd.RunCommand acCmdRecordsGoToNew
    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdPaste

'adding new info here...this line is commented out in VBA

    Me.Fieldname = "" 'first field you want to blank out
    Me.Fieldname2 = "" 'next field to blank out.
'etc etc etc

'then save it

   DoCmd.Save

Using double quotes ("") you turn strings in to null values. If you are going to blank out a date field you need to say = NULL

Now that the record is on the form and blanked out on the fields necessary, you also should make another button on the form to re-save the record after you edit it.
 
hello friends,
i have a form in my database and a field "Operator's Name" i want to make a button on my form that when i click on it, it will copy and paste this field value in next record in same(Operator's name) field.
how to do it please help.....
Thanks in advanced
 
Back