Append Query Functionality

MHamid

Active Member
Joined
Jan 31, 2013
Messages
472
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hello,

I am attempting to use an append query to move one record from onetable to another. I am using the below SQL code, but when I run it I get amessage stating that 2 rows will be appended, but I only want to append thecurrent record that is being viewed on a form. FYI - The tables being used haveall the same fields. Where did I go wrong?

Code:
[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000]INSERT INTO archive_RET_Accumulated[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000]SELECT RET_Accumulated.*[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000]FROM RET_Accumulated;[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000]

I will also need to delete the record (one record; currently selectedrecord) once it has been moved to the archive table. Would a query be best todo this?

Please note: there has been an issue when I type directly in the forum.So I have been typing these messages in word and copy/pasting into the forum.So some of my sentences/words may be missing spaces. That is not how it’s beingtyped it’s just how it’s being pasted for some reason.

Thank you

 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Where did I go wrong?
The code that you posted will insert ALL the record from your RET_Accumulated table unless you add a WHERE clause to your query with the conditions of the record(s) that you want to add.
 
Upvote 0
Hello,

I have added the WHERE piece to the code and now I get 0 records to append.

Code:
INSERT INTO archive_RET_Accumulated
SELECT RET_Accumulated.*
FROM RET_Accumulated, archive_RET_Accumulated
WHERE (((archive_RET_Accumulated.REF_NUM) Is Null));
 
Upvote 0
Get the "SELECT" part of the query working properly. When you get that, you can insert into the Append Query.

Note that I see you introduced a new table to the query (archive_RET_Accumulated), but didn't add any JOIN fields between the two tables.
You will most likely need to do that.
 
Upvote 0
Ok, I have added the JOIN field and it now wants to append all records from the RET_Accumulated table. Again, I just need the current record I am on in a form to be moved to the archive_RET_Accumulated table when I click on a button that is tied to a macro with this query. FYI, the archive_RET_Accumulated table is currently blank.

Code:
INSERT INTO archive_RET_Accumulated
SELECT RET_Accumulated.*
FROM RET_Accumulated LEFT JOIN archive_RET_Accumulated ON RET_Accumulated.[Exam ID] = archive_RET_Accumulated.[Exam ID]
WHERE (((archive_RET_Accumulated.[Exam ID]) Is Null));
 
Upvote 0
Do you have a primary key in your table?

If so, I would recommend capturing the value, and adding that into your code as your criteria. You may need to put that field on the form (if it is not already there). If you don't want it to be seen, you can always hide it.

If you need help doing that, please do the following:
- post the VBA code behind your button
- provide the name of the primary key field
- let us know the data type of the primary key field (Text, Integer, etc)
 
Upvote 0

Forum statistics

Threads
1,223,961
Messages
6,175,652
Members
452,664
Latest member
alpserbetli

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top