473,406 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 20514
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 that a series of new records may have the same...
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: DoCmd.RunCommand acCmdSelectRecord DoCmd.RunCommand...
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 need. I have only one issue: I need to copy the...
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 into duplicate(intId,varName) values(2,'raj12')...
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: CODE <?php $c=OCILogon("scott", "tiger",...
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 clicked so that the user will know that it has...
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 to create an event that will clear the two fields...
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 on the form: If DCount(search for records with...
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 and VBA so please take that into consideration. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.