473,386 Members | 1,743 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,386 software developers and data experts.

I need to duplicate records

I want to offer the option to duplicate a record in order to minimize input time if much or all of the record's information is the same, and allow the user to then go directly to the new record to make any slight modifications if there are any.

How do I do this?

Example:

Record 1:
Employee: 900
Date: 11/20/06
WO: 123456789
Scope: Automation
Start: 7:00 am
End: 6:30 pm
TtlTime: 11.5
RT: 11.5
OT: 0
ECO: 0
HOL: 0

Then the record opens and the employee changes the employee number to 901.

Thanks for any help offered!
Dec 10 '06 #1
4 1250
missinglinq
3,532 Expert 2GB
The Command Button Wizard offers the command "Duplicate a Record" but the problem is if any field is a Primary Key or otherwise doesn't allow Duplicates this throws an error. Below is a generic version of code that I use to accomplish this task. Behind a "Copy" command button, you basically copy the data from the current record to variables, go to a new record, then plug those variables into the new record.

Expand|Select|Wrap|Line Numbers
  1.  Private Sub CopyYourRecord_Click()
  2.    'Copy fields from original record to variables
  3.        NewField1 = Me.YourField1
  4.        NewField2 = Me.YourField2
  5.        NewField3 = Me.YourField3
  6.  
  7.        'Go to a new record
  8.        DoCmd.GoToRecord , , acNewRec
  9.  
  10.    'Plug in old values into new record
  11.    Me.YourField1.Value = NewField1
  12.       Me.YourField2.Value = NewField2
  13.       Me.YourField3.Value = NewField3
  14.  
  15.       'Now set the field your user wants to change to blanks
  16.       '(If any of these values would be numbers, use 0 [zero] instead of  "")  
  17.       Me.YourField4.Value = ""
  18.       Me.YourField5.Value = ""
  19.       Me.YourField6.Value = ""
  20.  
  21.      'If any of these fields to be changed is marked as Required in their    
  22.      'table's   Design Grid, leaving them blank will throw an error, so you'll
  23.      'need to change these to something like this: 
  24.      '(Same here, use 0 [zero] instead of  "" for numbers) 
  25.    Me.YourField4.Value = "Enter New Value for YourField4 "
  26.      Me.YourField5.Value = "Enter New Value for YourField5 "
  27.      Me.YourField6.Value = "Enter New Value for YourField6 "
  28. End Sub
  29.  
Now just follow the example and plug in your own control names.
Dec 10 '06 #2
NeoPa
32,556 Expert Mod 16PB
NewField1; NewField2; & NewField3 (your temporary variables) will need to be 'Dim'ed first though.
After the first line do :
Expand|Select|Wrap|Line Numbers
  1. Private Sub CopyYourRecord_Click()
  2.     Dim NewField1 As Variant, NewField2 As Variant, NewField3 As Variant
  3. ...
Dec 10 '06 #3
missinglinq
3,532 Expert 2GB
Only if you use Option Explicit, NeoPa. This code came from a very small form where I hadn't done that, although I ususally do. Runs and compiles just fine.
Dec 10 '06 #4
NeoPa
32,556 Expert Mod 16PB
Only if you use Option Explicit, NeoPa. This code came from a very small form where I hadn't done that, although I ususally do. Runs and compiles just fine.
I wouldn't argue with that, and I'm certainly not trying to find fault or criticize your contribution MissingLinq. It would be very bad manners for me to do that to anyone contributing answers to these forums. In your case it would also be very stupid (I hope I'm never that).
That said, I would always recommend (I'm sure you would too from what you say) that Option Explicit is used and that, even where it is absent, code should be written consistently with that option.
Dec 10 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Joe | last post by:
I used LOAD DATA FILE to load data into a mysql database. I discovered that there are lots of duplicate records. Can anyone give me a simple list of mysql commands to search and destroy duplicate...
1
by: Gary Lundquest | last post by:
It appears to me that MySQL version 4 returns an error messge when doing an Insert that results in duplicate entries. Version 3 did NOT return an error - it dropped the duplicate entries and ran...
10
by: Mark | last post by:
I have a table about people containing 25 fields. The table contains the usual fields - first, last, address, city, state and zip. There is no primary key. These fields all have data with the...
1
by: Danny | last post by:
I am trying to loop through a database and if a keyfield exists in another table, I need to duplicate it. What do you recommend? I assume I need to link the two based on the key field (fields...
2
by: Carroll | last post by:
I'm looking for a way in SQL to find duplicate records in a single table, that are the same based on 3 columns, regardless of what is in the other columns in the duplicate records. I would like to...
0
by: B.N.Prabhu | last post by:
Hi, I have a DataTable with several rows. Its having 20 Columns. when i click the Insert button then i have to check the Database Rows. Whether these new rows are already available in the...
2
by: nethravathy | last post by:
Hi, The following table namely elcbtripselect contains 5147 records.I want to know wether this table contains duplicate records or not. I tried with following query 1)SELECT...
1
by: aknoch | last post by:
My basic situation is this - I ONLY want duplicates, so the opposite of DISTINCT: I have two tables. Ordinarily, Table1ColumnA corresponds in a one to one ratio with Table2ColumnB through a...
6
by: Dilip1983 | last post by:
Hi All, I want to delete duplicate records from a large table. There is one index(INDEX_U1) on 4 columns(col1,col2,col3,col4) which is in unusable state. First of all when i tried to rebuild...
1
by: xraive | last post by:
I have a problem with this. Currently I am trying Allen's code and i am not successful. Current Design Table1 (Main Form) TravelID (PK) ApprovedBY EntreredBy BudgetCode ExpenseCode
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
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,...
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...

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.