Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
If ThisString > CVDate(ThisString) - 1 Then
[b]If Date <> CVDate(ThisString) Then[/b]
MsgBox "It is time to backup all the tables." & vbCrLf & vbCrLf & _
"When you click on OK, this will happen. You will receive a message once " & _
"this activity is complete.", vbInformation
For Each tbl In cat.Tables
If tbl.Type = "LINK" Then
mySQL = "SELECT * INTO " & tbl.Name & " IN '" & _
WhereFile & "' from " & tbl.Name
DoCmd.RunSQL mySQL
End If
Next
'If date on file is not today's date, then no backup has been made today.
If DateDiff("n", ThisString, Now()) > 60 Then _
MsgBox "It is time to backup all the tables." & vbCrLf & vbCrLf & _
"When you click on OK, this will happen. You will receive a message once " & _
"this activity is complete.", vbInformation
For Each tbl In cat.Tables
If tbl.Type = "LINK" Then
mySQL = "SELECT * INTO " & tbl.Name & " IN '" & _
WhereFile & "' from " & tbl.Name
DoCmd.RunSQL mySQL
End If
DoCmd.SetWarnings False
Next
' Write today's date to the text file. If the form that called this routine is opened again later today,
' nothing will happen.
Open ThisFile For Output As #1
Write #1, Now
Close #1
MsgBox "Today's backups have been made.", vbInformation
End Sub
Option Compare Database
Function dbBackup()
Call MakeBackupsADO(FileNamePattern:="Delivery_Backup_")
End Function
Public Sub CreateBackupTextFile()
' This sub presupposes the existence of a folder named BACKUPS, located in the directory in
' which this database is stored. It creates a text file there; the file will be used to
' determine whether daily backups of tables in this database have been made.
' This sub should be run only ONCE.
Dim DataPath As String
Dim ThisString As Variant
Dim ThisFile As String
Dim WhereFile As String
Dim TheDay As String
Dim FileNamePattern As String
' ----- Insert correct file name pattern here -------------------------------------------------
FileNamePattern = "Delivery_Backup_"
DataPath = "\\Eausrv01\Eau01a11\shared" & "\BACKUPS\"
TheDay = Day(Date)
If Len(TheDay) = 1 Then
TheDay = "0" & TheDay
End If
WhereFile = DataPath & FileNamePattern & TheDay & ".mdb"
ThisFile = DataPath & "\KeepThis_" & FileNamePattern & "File.txt"
' Write today's date to the file.
Open ThisFile For Output As #1
Write #1, Now
Close #1
MsgBox "The special text file required for backups has been created." & _
vbCrLf & vbCrLf & "It is named: " & ThisFile, vbInformation
End Sub
Public Sub CreateBackupDatabasesADO()
' This sub presupposes the existence of a folder named BACKUPS, located in the directory in
' which this database is stored.
' It creates 31 databases to be used to store daily backups of tables from this database.
' This sub should be run only ONCE.
Dim Ktr As Integer
Dim WhereFile As String
Dim TheDay As String
Dim DataPath As String
Dim FileNamePattern As String
Dim NameOfDB As String
Dim newDB As ADOX.Catalog
' ----- Insert correct file name pattern here -------------------------------------------------
FileNamePattern = "Delivery_Backup_"
DataPath = "\\Eausrv01\Eau01a11\Shared" & "\BACKUPS\"
WhereFile = DataPath & FileNamePattern
Set newDB = New ADOX.Catalog
For Ktr = 1 To 31
'Adjust the day to 2 characters
TheDay = Trim(CStr(Ktr))
If Len(TheDay) = 1 Then
TheDay = "0" & TheDay
End If
'Define the location and name of the new database
NameOfDB = WhereFile & TheDay & ".mdb"
'Create the database
newDB.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & NameOfDB
Next Ktr
Set newDB = Nothing
MsgBox "All databases have been prepared as " & WhereFile & "nn."
End Sub
Public Sub MakeBackupsADO(FileNamePattern As String)
' This subroutine presupposes the existence of 31 Access databases stored in a folder named BACKUPS
' in the same subdirectory where this database is stored.
' It also presupposes the existence of a text file (Example: KeepThis_MyDatabaseName_Backup_File.txt)
' stored in the BACKUPS folder.
' Every day, when this routine is first called, there is an automatic transfer of the data from all
' the tables into the backup database for that day of the month (example, MyDatabaseName_Backup_15.mdb).
' This routine should be called, for example, when the main form is loaded. An example:
' Private Sub Form_Load()
' DoCmd.Maximize
' Call MakeBackupsADO(FileNamePattern:="MyDatabaseName_Backup_")
' End Sub
Dim DataPath As String
Dim ThisString As Variant
Dim ThisFile As String
Dim WhereFile As String
Dim TheDay As String
Dim mySQL As String
Dim cat As New ADOX.Catalog
Dim tbl As Table
Set cat.ActiveConnection = CurrentProject.Connection
DataPath = "\\Eausrv01\Eau01a11\Shared" & "\BACKUPS\"
' Capture day of month of today's date
TheDay = Day(Date)
' Make it 2 characters
If Len(TheDay) = 1 Then
TheDay = "0" & TheDay
End If
' Get the date currently stored in the special text file
WhereFile = DataPath & FileNamePattern & TheDay & ".mdb"
ThisFile = DataPath & "\KeepThis_" & FileNamePattern & "File.txt"
Open ThisFile For Input As #1
Input #1, ThisString
Close #1
'If date on file is not today's date, then no backup has been made today.
If (DateDiff("n", ThisString, Now) < 60) = False Then _
DoCmd.SetWarnings False
MsgBox "It is time to backup all the tables." & vbCrLf & vbCrLf & _
"When you click on OK, this will happen. You will receive a message once " & _
"this activity is complete.", vbInformation
For Each tbl In cat.Tables
If tbl.Type = "LINK" Then
mySQL = "SELECT * INTO " & tbl.Name & " IN '" & _
WhereFile & "' from " & tbl.Name
DoCmd.RunSQL mySQL
End If
Next
' Write today's date to the text file. If the form that called this routine is opened again later today,
' nothing will happen.
Open ThisFile For Output As #1
Write #1, Now
Close #1
MsgBox "Backup made at " & Now(), vbInformation
Else: MsgBox "No backup needed as of " & Now()
End If
End Sub