Append only 1 record (1 Viewer)

txmmoore

Registered User.
Local time
Today, 01:57
Joined
Dec 4, 2014
Messages
18
I am trying to write an append query that will ONLY append the last record of one table into that of another table. Every time I try this, Access wants to Append all the records. How do you force it to only append the last record?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:57
Joined
May 7, 2009
Messages
19,232
it would be easier if you have AutoNumber field on your source table:

Insert Into TargetTable (a, b, c) Select Top 1 x, y, z From SourceTable Order By AutoField Desc;
 

txmmoore

Registered User.
Local time
Today, 01:57
Joined
Dec 4, 2014
Messages
18
So, something like this?

Insert Into Prerelease_info (ID Select) Select Top 1 [ID] From Customer_Info Order By AutoField Desc;

I get a Syntax error. I am new at this, so please help.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:57
Joined
May 7, 2009
Messages
19,232
what is the fieldname of autonumber field?
what are the field you want to insert?
dont include the autonumber in the insert.

if ID is autonumber field in your source table:

insert into Prerelease_info (targetFiel1, targetField2) Select Top 1 sourceField1, sourceField2 From Customer_Info Order By ID Desc;
 

txmmoore

Registered User.
Local time
Today, 01:57
Joined
Dec 4, 2014
Messages
18
Still having problems. Here is my summary:

Table1 -
ID - auto number
Name - Person's name

Table2 -
ID Select - Needs to be the same as ID in Table 1
Name - Needs to be the same as Name in Table 1

Please advise how the Insert command should look.

I only want to copy the last record in Table 1 into Table 2

Thank you!
 

plog

Banishment Pending
Local time
Today, 01:57
Joined
May 11, 2011
Messages
11,638
Why? Action queries are generally tools of people who don't fully understand how databases work. You shouldn't "move" data around a database. Instead you use data to identify special records.

Please explain what the difference between Table1 and Table2 is? If you could provide actual table names that would help as well. My guess is the actual solution to your real issue is the addition of a new field to Table1.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:57
Joined
May 7, 2009
Messages
19,232
Insert Into Prerelease_info ([ID Select],[Name]) Select Top 1 [ID],[Name] From Customer_Info Order By [ID] Desc;
 

txmmoore

Registered User.
Local time
Today, 01:57
Joined
Dec 4, 2014
Messages
18
Still get Syntax error!
See attached screen shot. Why can't access be easier!
 

Attachments

  • Capture.JPG
    Capture.JPG
    47.3 KB · Views: 84

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:57
Joined
May 7, 2009
Messages
19,232
you use DoCmd or DBEngine(0)(0).Execute:

DoCmd.RunSQL "Insert Into Prerelease_info ([ID Select],[Name]) Select Top 1 [ID],[Name] From Customer_Info Order By [ID] Desc;"

or

DbEngine(0)(0).Execute "Insert Into Prerelease_info ([ID Select],[Name]) Select Top 1 [ID],[Name] From Customer_Info Order By [ID] Desc;"
 

txmmoore

Registered User.
Local time
Today, 01:57
Joined
Dec 4, 2014
Messages
18
Thank you. That is exactly what I needed and it worked! Case Closed!
 

Users who are viewing this thread

Top Bottom