Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a Duplicate of an Existing Record in Microsoft Access but leave some fields blank.

Status
Not open for further replies.

priac

Technical User
Feb 8, 2002
47
US
I need to duplicate a record. Thats easy with the duplicate button, but I want the date field to be todays date and 2 other field to be blank. I am not a programmer and would like some help.
Thanks Aubrey
 
If that's your table:
[pre]
ID (AutoNumber) DateField Field1 Field2 Field3
1 1/1/2020 ABCD XYZ 765
2 2/2/2022 JHgy Hgb 123
3 3/3/2023 jhgg hgT 987
[/pre]
And you want to Copy record with ID = 2, I would try:
[tt]
INSERT INTO MyTable (DateField, Field1, Field2, Field3)
SELECT Date(), NULL, NULL, Field3 FROM MyTable Where ID = 2
[/tt]
Assuming Field1 and Field2 will accept NULLs, what you consider to be blank

(Not tested)

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Are you entering records into a form and want the new record to default to some values from the previous record? If so, this is typically accomplished by setting the default value of controls to the current values.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
I copy the complete record,(30 fields ) and erase 3 of them to be entered on the new record
 
Again, are you entering records into a form? That’s the appropriate way to create user interfaces. You could use a data sheet form which allows you to set default values.

30 fields is a lot especially if 27 might have duplicate values.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
Looks to me to be more like a spreadsheet than the table in normalized, relational data base...
[sad]

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
I am a pilot that flys test equipment for defense contractors. What happens is we complete a form with 30 fields on it . The form/field or the same for each mission with the exception of the date, a reference code, and hours. Now , I hit duplicate for each mission and change the date, reference code, and hours. I would like to hit duplicate and set the date field date(), and blank the reference code and hours. I add those after we land.
 
Did you try the code I gave you? Any luck? Any errors?
The code is not tested, but it should do exactly what you want.

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top