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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to move records from one table to another

Status
Not open for further replies.

e151280

IS-IT--Management
Feb 11, 2003
4
US
Greets, all.....

i'm a casual access user, who has wandered into waters that are too deep.

have 2 tables (table_a & table_b)related by a common id number... no referential integrity hassles because the tables already contain orphaned data that i have to keep.

what i'd like to do is this:

from the form that displays the data (displayform), create a button that will archive the selected record from table_a, and any related child records from table_b to a third & fourth table (arc_table_a, and arc_table_b). I'd then like to delete the now archived records from table_a & table_b. I have been trying to do this with an update query, with no success, and then i started looking for a way to do it programmatically. I also was wondering if SQL statements would work.

ex:

the open form has a field named 'id' that corresponds to the field names in the active and archive tables

select * from table_a where table_a.id = displayform.id
select * from table_b where table_b.id = displayform.id

am i headed in the right direction?

any assistence is appreciated.
 
You could create a macro that would be placed on the OnClick event of the button that runs some queries(OpenQuery action). The first would be an append query from table_a to arc_table_a (criteria would be [forms]![Formname]![table_aID]). Then the next would be a delete query using the same criteria on table_a. Then the third and fourth would do the same for table_b to arc_table_B and then delete again from table_b.
You would start your macro with Echo and Setwarnings equal to NO. Then at the end, reset them back to YES. Any book can show you how to create the append and delete queries.




 
How are ya e151280 . . .

By any chance are the id's [blue]autonumber![/blue]

Calvin.gif
See Ya! . . . . . .
 
The ID field is not autonumber... just an ordinary text field. it is unique in table_a, however, with multiple matching child records in table_b. same situation in arc_table_a and arc_table_b.
 
OK e151280 . . .

Hold the ID in a variable then:
[ol][li]Append the record from table_a to arc_table_a with an [blue]Append[/blue] query.[/li]
[li]Next append the records from table_b to arc_table_b with an [blue]Append[/blue] query.[/li]
[li]Repeat the above (in reverse order) using a [blue]Delete[/blue] query.[/li]
[li]Requery the form.[/li][/ol]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top