Save new record to different table with button macro - ms-access

I have an Access database and one of my tables is connected a form. I want to delete a record from my table and add it to another table with just one button. Deleting it is simple but I can't find a way to add the record to another table. Do you have any opinion on that?

1 Create 2 queries
An insert query
A delete query
2 Create a macro that has three actions
Open query( To run an append query)
Open query(To run a delete query)
A msg box, that will pop up to state that the two queries above ran
successfully
N:B
The insert and delete query will have parameters like record id
Attached is sample of insert query with parameter
The insert query in the macro condition should come first

Related

How to create batch jobs in Mysql?

I would like to create batch jobs in a Mysql database. To fetch data from child tables, and insert them into a master table, whenever the child table gets updated or new records got inserted.
How could I do this?
What you are looking for is called a trigger.
Triggers are functions executed when an update insert or delete action takes place on a specified table.
Read more here
http://www.mysqltutorial.org/mysql-triggers.aspx

MS Access "after insert" to replicate data accross different tables

I have 2 Identical tables and I want any data recorded in the first table to be automatically recorded in the 2nd table using data macros. Can anyone provide me with help on how to go about it?
After update, EXECUTE an INSERT INTO sql statement to the second table

How to automatically run a query when a table is amended by INSERT/UPDATE/DELETE?

I have a query which basically "syncs" all the data from a table in one database, to a replicated table in another database.
Here is the simple query:
TRUNCATE TABLE [Database2].[dbo].[USER_SYNC]
INSERT INTO [Database2].[dbo].[USER_SYNC]
SELECT * FROM [Database1].[dbo].[USER]
Now, after some research, I had a look into using a trigger to do this, however, I read up that stored procedures and heavy queries such as this should not be used within a trigger.
Therefore, what is the best way in which I can automatically run this query from within SQL, whenever a record in database1 is inserted, amended or deleted?
And if what I read up about triggers was incorrect, then how would I go about creating one for my procedure? Thanks.
If you need to sync tables you do not need to truncate one every time on update, delete or insert.
Create identical copy of user table.
Create on update, on delete, on insert triggers on the original user table.
In the trigger update, delete or insert to the duplicate table only one row at a time - the one that was updated, deleted or inserted to the original user table. This will not be a heavy query.
UPDATE:
http://www.mysqltutorial.org/create-the-first-trigger-in-mysql.aspx
http://dev.mysql.com/doc/refman/5.7/en/trigger-syntax.html

MySQL: Copy from 1 table to another not overwriting existing?

I have two tables:
tableOriginal
tableBackup
They have exactly the same structure.
I want a SQL statement I can run anytime of the day, that will copy all the rows from tableOriginal to tableBackup WITHOUT overwriting items in tableBackup. Basically, this command must synchronize tableBackup with tableOriginal.
How do I do that?
INSERT INTO tableBackup(SELECT * FROM tableOriginal)
As long as there is no issue with primary keys being updated or replaced with new incoming data this should not create an issue for you. However as you already know, backup table will have more data after your command since it did not delete previous data it had
Why don't you delete first all the data in tableBackup, then INSERT the data in tableOriginal to tableBackup
DELETE FROM tableBackup
INSERT INTO tableBackup(SELECT * FROM tableOriginal)
Why do we need to delete first?
Because if we're going to insert unique data into the tableBackup,
next time we insert it will not execute, because we will insert/add some data that is already been there..
Hope you get what I'm trying to say.

how to update the value of one table when the value is inserted in another table using mysql?

hi i have two tables namely
sms(Message,sms_index...columns)
c_paid_bribe(c_addi_info,....)
what i want to do is to insert the values of Message column of sms table into c_addi_info column of c_paid_bribe table automatically whenever a new value is inserted into sms table.
I tried this
$query=mysql_query("insert into bd_paid_bribe(c_addi_info) select Message from sms");
But when a new value is inserted and i run the .php file the already existed values are also inserting into the table again.....
Q: what i want to do is to insert the values of Message column of sms table into c_addi_info column of c_paid_bribe table automatically whenever a new value is inserted into sms table.
A: If you want to update one table when another is changed (and, for whatever reason, you can't simply do this in your application), then use "triggers":
http://net.tutsplus.com/tutorials/databases/introduction-to-mysql-triggers/
Q: But when a new value is inserted and i run the .php file the already existed values are also inserting into the table again.....
A: You want an "upsert". For example:
How do I update if exists, insert if not (AKA "upsert" or "merge") in MySQL?
What you want to do is simply to make two queries that are comitted in one transaction. This is what transactions are for. See here for examples on how to do it:
PHP + MySQL transactions examples