Private sub form_timer()
currentdb.execute "DELETE * FROM backuptable"
currentdb.execute "INSERT INTO backuptable SELECT * FROM maintable"
end sub
private sub form_load()
me.timerinterval=1000 *3600 'for 1 hour intervals (60 mins * 60 secs * 1000 units per second)
end sub
have a linked table for your backup table, then create a new form with he following vba code- something like
Code:Private sub form_timer() currentdb.execute "DELETE * FROM backuptable" currentdb.execute "INSERT INTO backuptable SELECT * FROM maintable" end sub private sub form_load() me.timerinterval=1000 *3600 'for 1 hour intervals (60 mins * 60 secs * 1000 units per second) end sub
note both database and form needs to be open to run
for windows scheduler, you will need access to the server windows scheduler, create a new db with linked tables to both backuptable and main table. Obviously,both db's will need to be on the server.
create a new module and a new public sub called say 'backup' and put the form_timer code in it together with another line
docmd.exit
to close the db once done. Then create an autoexec maco which calls this sub.
save the db.
Then use the server windows scheduler to open the db as required. Reference windows help for how the scheduler works.
Hi about above code, what if I want to run the code at 6PM daily? any way we can take local time of the system ?
create a new module and a new public sub called say 'backup' and put the form_timer code in it together with another line
docmd.exit
to close the db once done. Then create an autoexec maco which calls this sub.
save the db.
Option Compare Database
Option Explicit
Public Function Backup()
currentdb.execute "DELETE * FROM backuptable"
currentdb.execute "INSERT INTO backuptable SELECT * FROM maintable"
docmd.exit
end function
CJ,pretty much as already described
1. open new db
2. create linked tables to the original table in the main db and the backup table in the backup db
3. create a new module
4. put this code in the new module
5. Create a macro called autoexec to run the backup function (or I guess you can use the macro to run the 3 lines of code instead of having the backup functionCode:Option Compare Database Option Explicit Public Function Backup() currentdb.execute "DELETE * FROM backuptable" currentdb.execute "INSERT INTO backuptable SELECT * FROM maintable" docmd.exit end function
6. use windows scheduler to run the new db at the appointed time
docmd.exit