472,353 Members | 1,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

Create a duplicate record

Ray
I have a data input form and need to automatically duplicate the existing
record as a new record by clicking a button. The main purpose to duplicate
the record is that the new record is very similar to the existing record
with minor differences. It will save the data input operator a lot of
afford by editing the minor difference only. However, the new record is not
allowed to be saved if the operator forgets to make the modification for
whatever reasons to avoid duplicate records. Your guidance to accomplish it
is appreciated.

Thanks,

Ray

Nov 13 '05 #1
8 20322
Here's ADO code for a copy button I use. This is a bound form with a
listbox containing the list of addresses, with the bound column being the
primary key. Start Date is the only change required.
================================
Private Sub btnCopy_Click()
On Error GoTo handle_error
Set cnxn = CurrentProject.Connection
Set rs = New ADODB.Recordset
If IsNull(Me.lstRecords.Value) Then
MsgBox "No item selected", , "Selection Needed"
Else
With rs
.Open "address", cnxn, adOpenKeyset, adLockOptimistic,
adCmdTableDirect
.Index = "PrimaryKey"
.Seek Me.txtId.Value, adSeekFirstEQ
If Not .EOF Then
DoCmd.RunCommand acCmdRecordsGoToNew
Me("add_off_id") = .Fields("add_off_id")
Me("add_state_id") = .Fields("add_state_id")
Me("add_residtype_id") = .Fields("add_residtype_id")
Me("add_house_no") = .Fields("add_house_no")
Me("add_apt") = .Fields("add_apt")
Me("add_street_id") = .Fields("add_street_id")
Me("add_zip_id") = .Fields("add_zip_id")
Me("add_loc_id") = .Fields("add_loc_id")
Me("add_map_id") = .Fields("add_map_id")
End If
.Close
End With
Set rs = Nothing
Me.txtStartDate.SetFocus
End If
Exit Sub
handle_error:
LogError Err.Number, "AddressForm.btnCopy", Err.Description '
Error-logging sub
End Sub
============================
You could add code that stored the old start date, and compared it to the
new start date, and did not allow a save if they were the same.
Darryl Kerkeslager
"Ray" <No**************@Yahoo.com.hk> wrote in message
news:33*************@individual.net...
I have a data input form and need to automatically duplicate the existing
record as a new record by clicking a button. The main purpose to duplicate the record is that the new record is very similar to the existing record
with minor differences. It will save the data input operator a lot of
afford by editing the minor difference only. However, the new record is not allowed to be saved if the operator forgets to make the modification for
whatever reasons to avoid duplicate records. Your guidance to accomplish it is appreciated.

Nov 13 '05 #2
rkc
Ray wrote:
I have a data input form and need to automatically duplicate the existing
record as a new record by clicking a button. The main purpose to duplicate
the record is that the new record is very similar to the existing record
with minor differences. It will save the data input operator a lot of
afford by editing the minor difference only. However, the new record is not
allowed to be saved if the operator forgets to make the modification for
whatever reasons to avoid duplicate records. Your guidance to accomplish it
is appreciated.


If you mean you want to carry the current values of the controls
over into a new record to be entered using the same form then:

Look up DefaultValue using the Help system.
The easiest way to do that is to open a code module,
type defaultValue, place the cursor over the word and
hit F1.

After you have read that go here:

http://www.mvps.org/access/forms/frm0012.htm

then here:

http://www.mvps.org/access/forms/frm0027.htm
After you have read that try this:

Private Sub cmdSetDefaultValues_Click()
Dim ctl As Access.Control

On Error Resume Next

For Each ctl In Me.Controls
ctl.defaultValue = """" & ctl.Value & """"
Next

If Not ctl Is Nothing Then Set ctl = Nothing

End Sub

Nov 13 '05 #3
This is the problem I have with Access. Look at this answer!
Private Sub btnCopy_Click()
On Error GoTo handle_error
Set cnxn = CurrentProject.Connection
Set rs = New ADODB.Recordset
If IsNull(Me.lstRecords.Value) Then
MsgBox "No item selected", , "Selection Needed"
Else
etc.etc.etc.

When I used Lotus Approach, there was an icon and a dropdown command to
duplicate the record presently being displayed. That was it!

I saved a reply from a while back to the same question I posed:
For instance, duplicating a record is a handy button to have, but there is

none

Here's the reply I got:

"There is one...just click the Command Button icon on the Toolbox and pick
the Records Category and choose Duplicate Record from the right side."

But, how do I get the Tool Box to appear? When I have a record open in Forms, I
see no icon for Toolbox, I see it in no dropdown menu, and when I enter
"toolbox" in Help, there is nothing about how to access it. When I finally got
the toolbox to appear, from some options menu (I think), it was completely
grayed when I had a record open in Forms.

Neil
Cat Paintings At Carol Wilson Gallery
http://www.carolwilsongallery.com
Nov 13 '05 #4
I just found that the Edit menu can be used: select the record, copy, Enter
(for new blank record), paste. After that you have to hit Paste Append for a
third duplicate and after. Not just one click, but better than nothing. Why
isn't this in the Help system?

Neil
Cat Paintings At Carol Wilson Gallery
http://www.carolwilsongallery.com
Nov 13 '05 #5
nh******@aol.comnojunk (Nhmiller) wrote:
That Duplicate Record Button is GREAT -

BUT I get error messages, linked to this:
Private Sub Combo94_AfterUpdate()
Me.FilterOn = False
DoCmd.GoToControl "[IDae]"
DoCmd.FindRecord Forms![Grant3AEModified]![Combo94]
End Sub

The FilterOn is highlighted as the offending statement -
Another combo box event interferes too.
I've got some "required' fields in the record.

If I go to the Table select the record; copy; paste append - it works
without errors.
Any ideas?

Here's the reply I got:

"There is one...just click the Command Button icon on the Toolbox and pick
the Records Category and choose Duplicate Record from the right side."

But, how do I get the Tool Box to appear? When I have a record open in Forms, I
see no icon for Toolbox, I see it in no dropdown menu, and when I enter
"toolbox" in Help, there is nothing about how to access it. When I finally got
the toolbox to appear, from some options menu (I think), it was completely
grayed when I had a record open in Forms.

Neil
Cat Paintings At Carol Wilson Gallery
http://www.carolwilsongallery.com

-warning e-mail address altered- arthureNOSPACE@
Nov 13 '05 #6
I have a problem with the duplicate record button however...

when I do minor changes on the duplicate, it erases the values of the
original. how can I make the two records independent of each other?

is there some sort of "ok, i'm done copying, now break the
relationship" kind of code?

help!

Nov 13 '05 #7
Information Queen wrote:
I have a problem with the duplicate record button however...

when I do minor changes on the duplicate, it erases the values of the
original. how can I make the two records independent of each other?

is there some sort of "ok, i'm done copying, now break the
relationship" kind of code?

help!

Usually the record should be saved first.

You might want to look at the Runcommand method of Docmd. I don't know
if these will work...you may want to look at the constants.
Docmd.Runcommand acCmdSaveRecord
Docmd.Runcommand acCmdDuplicate 'unsure of this one
You could put this code behind a command button or make a new menu bar
option.
Nov 13 '05 #8
yup, i ran into the "the duplicate command is not available now.

here is the code behind the duplicate button..

Private Sub cdmDuplicate_Click()
On Error GoTo Err_cdmDuplicate_Click
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdSaveRecord
DoCmd.RunCommand acCmdCopy
DoCmd.RunCommand acCmdPasteAppend

Exit_cdmDuplicate_Click:
Exit Sub

Err_cdmDuplicate_Click:
MsgBox Err.Description
Resume Exit_cdmDuplicate_Click

End Sub

Nov 13 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Mark | last post by:
When my form goes to a new record, I have a procedure that copies the last record added to the form's underlying table into the form. The intent is...
1
by: 2D Rick | last post by:
Access2003 in XP If I open a form to a specific record and click on a command button with the following code I get a duplcate record: ...
3
by: ammie65 | last post by:
I have been trying to create a purchase order database in Access, and I have been successful in creating all the tables, queries and reports that I...
3
by: rajeshkrsingh | last post by:
Hi friends, Step1- create table duplicate ( intId int, varName varchar(50) ) insert into duplicate(intId,varName) values(1,'rajesh') insert...
6
by: teser3 | last post by:
I have my PHP inserting into Oracle 9i. But how do I prevent duplicate record entries? I only have 3 fields in the insert in the action page: ...
3
by: mlb992000 | last post by:
I have a form that has a duplicate record command button and I need to create an event that will clear two of the fields once the duplicate record is...
1
by: mlb992000 | last post by:
I have a form that has a duplicate record command button that allows the user to duplicate all information on the form and change two fields. I need...
2
by: Ranma13 | last post by:
Hello, I have a duplicate record check written in VB for a check in/check out database. Here's the pseudocode, written for the BeforeUpdate property...
3
by: JMANTN | last post by:
Hello, I'm hoping someone could help me out with a problem I've ran into while trying to create a training database. I'm just a beginner with Access...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.