At one of the contracts I am on currently, I run several backup procedures through out the day on some of the main tables if something should happen while I’m not on site.
I set up a simple process. I am letting the Windows Task Scheduler, which runs as a service while the computer is on, open a database which performs the backup process, and then closes again.
I am launching a task on an hourly basis, so I don’t have to keep the database open all day.
Here is a list of procedures I am running:
I open the Task Scheduler and “Create Basic Task” (this particular one runs at 1pm daily).
(Program/Script):
This will open the MS Access 16 program on your computer:
“C:\Program Files (x86)\Microsoft Office\Office16\MSACCESS.EXE”
(Add Arguments (optional)):
Now point to the path of your database:
“\\server\share\folder\backups\backup.accdb”
I didn’t do anything specific for this
The History tab just shows the outcome of your task.
So the way it works, is that when the Scheduled Task runs, a database is opened, which launches a hidden form in the database and runs my VBA code.
When the database opens, a form is launched:
The code in the “Load” event of the form is…
Private Sub Form_Load() MakeBackup Call btnProjBak_Click Application.Quit End Sub Private Sub btnProjBak_Click() '3/12/18 - ejl Dim strFile As String Dim strDestination As String Dim qdf1 As DAO.QueryDef Dim strSQL1 As String Dim qdf2 As DAO.QueryDef strFile = Format(Time, "hhmm") & "_" & Format(Date, "YYYYmmdd") & "_Projects.csv" Set qdf1 = CurrentDb.QueryDefs("qryPPProjects") strSQL1 = qdf1.SQL Set qdf2 = CurrentDb.QueryDefs("qryPPProjects_Export") qdf2.SQL = strSQL1 strDestination = "\\server\share\backups\interface\" & strFile DoCmd.TransferText acExportDelim, , "qryPPProjects_Export", strDestination, True '--------------------------------------------------------------------------- strFile = Format(Time, "hhmm") & "_" & Format(Date, "YYYYmmdd") & "_ProjectItems.csv" Set qdf1 = CurrentDb.QueryDefs("qryPPProjectItems") strSQL1 = qdf1.SQL Set qdf2 = CurrentDb.QueryDefs("qryPPProjectItems_Export") qdf2.SQL = strSQL1 strDestination = "\\server\share\backups\interface\" & strFile DoCmd.TransferText acExportDelim, , "qryPPProjectItems_Export", strDestination, True '--------------------------------------------------------------------------- qdf1.Close qdf2.Close Set qdf1 = Nothing Set qdf2 = Nothing End Sub
Here’s a part of what the folder looks like after this process is done.
That way if I am not around, they have all the vital data to keep them running smoothly until I return 🙂
Let me know if you have any questions.
How To Escape Apostrophe In SQL Update Query
If you are looping a table with thousands of records, you’ll probably run into at least one that has an apostrophe in the field name. Like “Mike’s” or “M’cormick”, or something else. Anyway, here is one way to escape the string when you are doing your update query. Option Compare Database Sub YDriveLoop() ‘4/23/24 erik@loeblcomservices.com […]
How To Parse A Flat File In Excel VBA
In another post I demonstrated how to access a file on your computer using the MS Office Library. Here it is if you don’t know what I’m talking about. In this post, I am going to show you how to access the file and load it into your spreadsheet. I will do the same thing […]
How can I interact with other Office applications (Excel) using VBA in Access?
Need to write your Access data or query to an Excel file? Here is the how to do it: Most people are familiar with Excel and know how to use it well (enough), and when you start talking about Access, they get scared off, and don’t know what to do anymore. Well, here you are […]
How To Create A Parameter Query In Access
A parameter query changes your ordinary static access query to be more dynamic and interactive. It will ask you a question about what you want to search for, allowing you to do a search query multiple times instead of just once. You can do your parameter query straight from the QBE (Query By Example) Editor, […]