Delete two tables

oxicottin

Learning by pecking away....
Local time
Yesterday, 19:07
Joined
Jun 26, 2007
Messages
889
I have two different tables and I need to run a delete query to delete all information pertaining to an employee when he/she is expired threw a button on a continious form which uses one of the tables that needs deleted. How would I do this and please explain in newbie terms.....Thanks!
 
You could put SQL delete query on OnClick event of button.


Create delete query in query designer. Test it and see if it works fine.

Go to your form and on OnClick event in VBA type:

Docmd.Setwarnings = false -- hide the system message

Docmd.runquery "NameOfQuery" -- not sure if this is excat command (type docmd.run -- you will see then)

docmd.Setwarnings = true -- restore system message
 
The exact command would be docmd.openquery("QueryName"). Also if you turn off the warnings make sure you turn them back on.
 
I have two different tables and I need to run a delete query to delete all information pertaining to an employee when he/she is expired threw a button on a continious form which uses one of the tables that needs deleted. How would I do this and please explain in newbie terms.....Thanks!
More info

There are two methods that are good for action queries..."DoCmd.RunSQL", and "currentdb.execute". They both will work for a "DELETE" SQL statement, because this is an ACTION type query. If I were going to delete all information about a customer from two different tables (customers and invoices), that were joined on a one-to-many relationship, I would write this with an OnClick event...
Code:
DoCmd.RunSQL "DELETE * FROM table INNER JOIN othertable on Field = Field 
     WHERE customers.customer = TheCustomersName
This is not correct of course, but the actual SQL you will write, you can get by using the query grid, like Luka said earlier.
 

Users who are viewing this thread

Back
Top Bottom