I have a record which l would like to duplicate 5 times , is there any way l can duplicate this record rather than type it out five times?
see attachment. Obvioulsy l could copy and paste each line , but is there an easier way?
Justin.
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Pasting records (2000)
Should the fields in the current main record (Dave Regan etc.) be copied into the new main record?
What is the name of the table that contains the main record?
What is the name of the table that contains the subrecords?
On what field or fields are the main record and the subrecords linked? I want to know the field name(s) and data type(s) on the side of the main record, and also on the side of the subrecords.
Should the fields in the current main record (Dave Regan etc.) be copied into the new main record? (Yes)
What is the name of the table that contains the main record? (Despatch Note)
What is the name of the table that contains the subrecords? (Despatch Note Items)
On what field or fields are the main record and the subrecords linked? I want to know the field name(s) and data type(s) on the side of the main record, and also on the side of the subrecords.
They are linked by Despatch Note Number which is an auto number.
Justin.
I would put a text box txtNumber on the form in which the user can enter the number of copies to be made, and a command button cmdCopy that performs the copy action. The On Click event procedure for the command button is below. Since I don’t know the names of all fields in the subtable, you must complete the list of fields in the code.
Private Sub cmdCopy_Click()
Dim lngOldPK As Long
Dim lngNewPK As Long
Dim i As Long
Dim lngNumber As Long
Dim strSQL As String
On Error GoTo ErrHandler
If IsNull(Me.[Despatch Note Number]) Then
MsgBox “Can’t copy blank record.”, vbExclamation
Exit Sub
End If
If Val(Nz(Me.txtNumber, 0)) <= 0 Then
MsgBox "Please enter a valid number.", vbExclamation
Me.txtNumber.SetFocus
Exit Sub
End If
If Me.Dirty Then
RunCommand acCmdSaveRecord
End If
lngNumber = CLng(Me.txtNumber)
lngOldPK = Me.[Despatch Note Number]
DoCmd.SetWarnings False
Echo False
For i = 1 To lngNumber
RunCommand acCmdSelectRecord
RunCommand acCmdCopy
RunCommand acCmdPasteAppend
lngNewPK = Me.[Despatch Note Number]
RunCommand acCmdSaveRecord
' Note: add the fields you want to copy in both lists
strSQL = "INSERT INTO [Despatch Note Items] " & _
"( [Despatch Note Number], Item, Description ) " & _
"SELECT " & lngNewPK & " As [Despatch Note Number], Item, Description " & _
"FROM [Despatch Note Items] " & _
"WHERE [Despatch Note Number] = " & lngOldPK
DoCmd.RunSQL strSQL
Next i
ExitHandler:
DoCmd.SetWarnings True
Echo True
Exit Sub
ErrHandler:
MsgBox Err.Description, vbExclamation
Resume ExitHandler
End Sub
I have attached a working demo with a limited number of fields.
I would put a text box txtNumber on the form in which the user can enter the number of copies to be made, and a command button cmdCopy that performs the copy action. The On Click event procedure for the command button is below. Since I don’t know the names of all fields in the subtable, you must complete the list of fields in the code.
Private Sub cmdCopy_Click()
Dim lngOldPK As Long
Dim lngNewPK As Long
Dim i As Long
Dim lngNumber As Long
Dim strSQL As String
On Error GoTo ErrHandler
If IsNull(Me.[Despatch Note Number]) Then
MsgBox “Can’t copy blank record.”, vbExclamation
Exit Sub
End If
If Val(Nz(Me.txtNumber, 0)) <= 0 Then
MsgBox "Please enter a valid number.", vbExclamation
Me.txtNumber.SetFocus
Exit Sub
End If
If Me.Dirty Then
RunCommand acCmdSaveRecord
End If
lngNumber = CLng(Me.txtNumber)
lngOldPK = Me.[Despatch Note Number]
DoCmd.SetWarnings False
Echo False
For i = 1 To lngNumber
RunCommand acCmdSelectRecord
RunCommand acCmdCopy
RunCommand acCmdPasteAppend
lngNewPK = Me.[Despatch Note Number]
RunCommand acCmdSaveRecord
' Note: add the fields you want to copy in both lists
strSQL = "INSERT INTO [Despatch Note Items] " & _
"( [Despatch Note Number], Item, Description ) " & _
"SELECT " & lngNewPK & " As [Despatch Note Number], Item, Description " & _
"FROM [Despatch Note Items] " & _
"WHERE [Despatch Note Number] = " & lngOldPK
DoCmd.RunSQL strSQL
Next i
ExitHandler:
DoCmd.SetWarnings True
Echo True
Exit Sub
ErrHandler:
MsgBox Err.Description, vbExclamation
Resume ExitHandler
End Sub
I have attached a working demo with a limited number of fields.
Should the fields in the current main record (Dave Regan etc.) be copied into the new main record? (Yes)
What is the name of the table that contains the main record? (Despatch Note)
What is the name of the table that contains the subrecords? (Despatch Note Items)
On what field or fields are the main record and the subrecords linked? I want to know the field name(s) and data type(s) on the side of the main record, and also on the side of the subrecords.
They are linked by Despatch Note Number which is an auto number.
Justin.
Should the fields in the current main record (Dave Regan etc.) be copied into the new main record?
What is the name of the table that contains the main record?
What is the name of the table that contains the subrecords?
On what field or fields are the main record and the subrecords linked? I want to know the field name(s) and data type(s) on the side of the main record, and also on the side of the subrecords.
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.