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

Button to make a duplicate record

Status
Not open for further replies.

kuebs

Technical User
Mar 6, 2002
15
US
I want to create a button that has a macro that will make a duplicate of the last record, and then the user can change one or two items? This is to save them a lot of data entry. Is this possible? I would use VBA also if that helps.
 
This might be a bit long and tedious but what you can do is this:

Dim value1 As Variant 'value of field you want to copy to new rec

If MsgBox("Would you like to copy data across from this record to the new record?", vbYesNo, "NEW RECORD") = 6 Then
value1 = Me![fieldname]
DoCmd.GoToRecord , , acNewRec
Me![fieldname] = value1
Else
DoCmd.GoToRecord , , acNewRec


Hope that helps.

wah
 
Thanks for your help. I actually took a programming course 4 years ago, that used VBA as the programming language, but I can't seem to get the code into the macro builder. I think I understand what the code is trying to do, but I can't get it entered in the right place.
 
No, I just want a button that will make a duplicate entry, that the user can then edit the few items that are different. I can use VBA or anything else you think is appropriate.
 
Then all you have to do is create a button (which you can find on the tool bar menu) and then bring up the properties for that button. In the event section click the ... button next to the on_click event. Choose code and it will open up a new window of code. Enter the before mentioned code (changed to suit your needs) and u r done! If you have any probs let me know (robbb@ealing.gov.uk)

cheers
wah
 
Don't do it!!! If your have duplicate records, then you've lost your referential integity.....

A better way to do this is to use the After_Update event on each box to set a default value for each control, not duplicate a record.....

Therefore, the variable bits can be set to not have values on new records but the other bits can change.......

Hope that helps.......

Craig
 
thats true. I'm assuming you have a unique number for each record (ie autonumber) that you wernt interested in copying over. If you do have then the way i suggested will work as the records wont be identical (ie the autonumber will set them apart). If not then you may want to think about giving each record a unique identifier.
 
I do have a field with a unique number that is autonumbered, and as long as it makes a distinct copy, I assumed it would be autonumbered to the next record.
 
yup thats how it will work! Just copy accross the fields that are most likely to be needed for the new record. It doesnt even have to be the last record that will be copied, just any record the user is currently viewing.

wah
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top