View Full Version : deleting and adding records


lloydmav
01-07-2003, 08:45 AM
Lets say I have two tables, table 1 and table 2.

I want to delete all the records in table 2 whose Action_Plan_ID field = "12"(12 just an example)

Then I want go to every record in Table 1 and if the Action_Plan_ID field in there = "12" I want to add all those records to Table 2.

I need to beable to do all this by the click of a button.

Can anyone give me the code for doing that

Thanks

pdx_man
01-07-2003, 01:57 PM
Do you want to eat the Fish, or do you want to learn how to Fish? :)

Create a Delete query with criteria '12' on table2
Create an Append query with table1 appending to table2

Use the OnClick event of a command button on a form to run both queries.

barbarossaii
01-07-2003, 02:09 PM
Hi lloydmav,

although I am no Access-programmer I can give you some hints how to solve your problem.

Create a Delete Query (=Action-query; see also MS-Access help), which deletes the records in table2 , include under Criteria of 'column' Action_Plan_ID:
="12"
or
=12
(depending on if its txt/number). When you run this query it should Delete the records of tbl 2 containing 12 for good.

Create an Amend query (=action query, too). This will amend table2 with the records of table 1 (containin 12). The criteria is the same as above.

Create a macro that runs the delete query first and then the amend query. You can link the execution of this macro to a button on a form or simply execute the macro.


HTH,
Barbarossa II


PS: pdx_man was faster than me......

lloydmav
01-08-2003, 01:05 AM
Ok, thanks guys for the help,

I know it was a simple question but I was in a rush (1 minute before finishing work) I was getting lazy!

Thanks for the help