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

Duplicate a Record

Status
Not open for further replies.

MaggieLeatherman

Programmer
May 9, 2004
59
0
0
US
Hi, I have an input form where the user would like to duplicate all the information into a new record and then only change Room Number. This would save data entry time since much of the data is the same except for changing the room number. I'm not sure how to accomplish this task...

Thanks for all you help, Maggie
 

TheCommand Button Wizard has an option to Copy a Record, the problem being that if you have a Primary Key, which you probably should, it'll throw an error and won't allow the copy! Here's what I use, although, as my signature suggests, there's probably other ways!

Code:
Private Sub CopyRecord_Click()
  'Copy fields to variables
  My1stField = Me.FirstField
  My2ndField = Me.SecondField
  My3rdField = Me.ThirdField

  'Go to a new record
  DoCmd.GoToRecord , , acNewRec

  'Prompt to enter new Room Number
  Me.RoomNumber.Value = "Enter New Room Number"

  'Plugs old values into new record
  Me.FirstField.Value = My1stField
  Me.SecondField.Value = My2ndField
  Me.ThirdField.Value = My3rdField
End Sub

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Thank you so much for this code. I know it will work... Now another important part that I negelected to ask... How do I add the matching Detail records in the subform?

In other words, Main form (frmArea) has a subform (subMaterials) When I duplicate the records from frmArea I also want to duplicate the 2 or 3 or howmany details that go with the Master record..

Thanks for your help....
 

You'll have to look elsewhere for help with that, Maggie! I avoid subforms like the plague! The problems they cause usually outweigh the benefits, at least in my practice. Someone else here will fill the gap!

Good Luck!

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Hi The Missinglinq!
Thanks for all your help. I have another question regarding your first post with the code..
Will you explain this? How do you make this work?
'Prompt to enter new Room Number
Me.RoomNumber.Value = "Enter New Room Number"

How do you make a prompt for the user to enter the room#?

Thanks, Maggie
 

Sorry, bad choice of words!

Me.RoomNumber.Value = "Enter New Room Number"

simply makes the words Enter New Room Number appear in the text box for the room number. If the text is too long or you simply don't want to use it, you can omit this line and the control for the room number will be blank, waiting for the user to fill in.

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 

missingling... subforms ROOL!

Give em another chance... all they need is the right connektion.

judst my thoughts
Don
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top