473,785 Members | 2,476 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 20552
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.lstRe cords.Value) Then
MsgBox "No item selected", , "Selection Needed"
Else
With rs
.Open "address", cnxn, adOpenKeyset, adLockOptimisti c,
adCmdTableDirec t
.Index = "PrimaryKey "
.Seek Me.txtId.Value, adSeekFirstEQ
If Not .EOF Then
DoCmd.RunComman d acCmdRecordsGoT oNew
Me("add_off_id" ) = .Fields("add_of f_id")
Me("add_state_i d") = .Fields("add_st ate_id")
Me("add_residty pe_id") = .Fields("add_re sidtype_id")
Me("add_house_n o") = .Fields("add_ho use_no")
Me("add_apt") = .Fields("add_ap t")
Me("add_street_ id") = .Fields("add_st reet_id")
Me("add_zip_id" ) = .Fields("add_zi p_id")
Me("add_loc_id" ) = .Fields("add_lo c_id")
Me("add_map_id" ) = .Fields("add_ma p_id")
End If
.Close
End With
Set rs = Nothing
Me.txtStartDate .SetFocus
End If
Exit Sub
handle_error:
LogError Err.Number, "AddressForm.bt nCopy", 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******** *****@individua l.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 cmdSetDefaultVa lues_Click()
Dim ctl As Access.Control

On Error Resume Next

For Each ctl In Me.Controls
ctl.defaultValu e = """" & 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.lstRe cords.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.co mnojunk (Nhmiller) wrote:
That Duplicate Record Button is GREAT -

BUT I get error messages, linked to this:
Private Sub Combo94_AfterUp date()
Me.FilterOn = False
DoCmd.GoToContr ol "[IDae]"
DoCmd.FindRecor d Forms![Grant3AEModifie d]![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.Runcomman d acCmdSaveRecord
Docmd.Runcomman d 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_Cl ick()
On Error GoTo Err_cdmDuplicat e_Click
DoCmd.RunComman d acCmdSelectReco rd
DoCmd.RunComman d acCmdSaveRecord
DoCmd.RunComman d acCmdCopy
DoCmd.RunComman d acCmdPasteAppen d

Exit_cdmDuplica te_Click:
Exit Sub

Err_cdmDuplicat e_Click:
MsgBox Err.Description
Resume Exit_cdmDuplica te_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
3306
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 data in many of the fields so I paste in the same values of the previous record and then edit what needs edited in the new record saving much retyping of the same data. Doing this however creates the definite possibility of creating a duplicate...
1
9048
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 acCmdSaveRecord DoCmd.RunCommand acCmdCopy DoCmd.RunCommand acCmdPasteAppend OR DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
3
2375
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 PO - which has a relationship set up as one-to-many with a subform that includes the PO items (Qty, Desc & Price). I want to be able to create a duplicate record using a simple command button, that not only duplicates the main record, but includes all...
3
10948
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') insert into duplicate(intId,varName) values(1,'rajesh')
6
4549
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", "orcl"); if ( ! $c ) { echo "Unable to connect: " . var_dump( OCIError() );
3
1457
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 been clicked. Can anyone help me create this event or any event that will notify the user that the duplicate record button has been clicked?
1
2301
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 once the duplicate record is clicked so that the user will know that it has been clicked. Can anyone help me create this event or any event that will notify the user that the duplicate record button has been clicked?
2
2550
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 the same TimeIn and TimeOut) > 0 Then MsgBox("Duplicate record found") Undo and set focus End Sub This code works fine if you try to add a new record that has duplicate times for TimeIn and TimeOut, but when I try to modify an...
3
2102
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. The problem I'm having is the possibility of record duplication in my current database. I'm hoping maybe there's a way to set up a relationship or query/vba to prevent this. I currently have a form (frmCE_AddAgentTraining) which I use to select...
0
9481
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10341
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10095
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7502
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.