Create a Button to Duplicate Current Record (1 Viewer)

PotatoPancakes

New member
Local time
Yesterday, 16:26
Joined
Aug 19, 2015
Messages
8
I am looking for a way to duplicate the current record (in List view) all but one field (well, technically two - can't duplicate the ID column). I have 25 fields that need to be populated for each entry and a lot of records are similar except for a field or two.

How would I go about achieving this? My thought is to create a macro but I'm having a hard time wrapping my head about how to get the (short) list actions to do what I want. I'm open to any other suggestions.

If it's necessary, I'm running version 15.0.4727.1003 of Access to edit the web app hosted on my company's SharePoint site.
 

Ranman256

Well-known member
Local time
Yesterday, 19:26
Joined
Apr 9, 2015
Messages
4,339
build a append query to append to the current table using the record you are currently on using the keyID ,(but dont append the ID

INSERT INTO table (Name, state)
SELECT [Name], State
FROM table WHERE (((ID)=[Forms]![frmList]![ID]));

the button would run this query
docmd.setwarnings false
docmd.openquery "qaMakeCopy"
 

PotatoPancakes

New member
Local time
Yesterday, 16:26
Joined
Aug 19, 2015
Messages
8
Won't this only work for a desktop database? The web app can't run append queries.
 

JulianKirkness

Registered User.
Local time
Today, 00:26
Joined
Apr 15, 2015
Messages
14
Hi


You're correct that AWAs don't have append queries - so the only option open to you is to use a data macro to crete a new record and set all the field values you wish to duplicate. This could be called from a button in the UI.

Essentially, the macro would:

Lookup a record (the one to copy) - using the ID - use an alias, say OldRecord
Create a new record - Alias NewRecord
Edit the new record
Use SetField to set the NewRecord.Fieldname values to OldRecord.fieldname values

Hopefully this should give you an idea how to proceed - shame there aren't any Append queries!
 

PotatoPancakes

New member
Local time
Yesterday, 16:26
Joined
Aug 19, 2015
Messages
8
Thank you JulianKirkness. I ended up figuring it out on my own using a Macro (not a datamacro). For anyone curious, I'll post my code below. All I did was use the ID to set a variable for each value I wanted to copy, created a new record, and set the individual fields to the variables I had set. Tedious and annoying to do, but it works.

One thing I discovered while doing this was that the naming of a Macro can cause errors. Right or wrong, I name my macros "Macro_XXX" which has always worked for me. However, it doesn't work for this macro. No idea why. If I change the name to "Copy" it works, but not "Macro_Copy".

 

Number11

Member
Local time
Today, 00:26
Joined
Jan 29, 2020
Messages
607
Thank you JulianKirkness. I ended up figuring it out on my own using a Macro (not a datamacro). For anyone curious, I'll post my code below. All I did was use the ID to set a variable for each value I wanted to copy, created a new record, and set the individual fields to the variables I had set. Tedious and annoying to do, but it works.

One thing I discovered while doing this was that the naming of a Macro can cause errors. Right or wrong, I name my macros "Macro_XXX" which has always worked for me. However, it doesn't work for this macro. No idea why. If I change the name to "Copy" it works, but not "Macro_Copy".

Please could we see your code?
 

jdraw

Super Moderator
Staff member
Local time
Yesterday, 19:26
Joined
Jan 23, 2006
Messages
15,379
Number11,
You have responded to an old thread. Access Web Apps have been discontinued/no longer supported.
If you have a specific question, I recommend you start a new thread.
Good luck.
 

Users who are viewing this thread

Top Bottom