I have a database with multiple forms and I would like to on close I would assume of the form, save a backup to a specific folder. This will all change once I move the database to the server but for now want a backup on my machine.
Here is my code:
Code:
Private Sub Form_Close()
Call db_backup
End Sub
Below is in a module
Code:
Option Compare Database
Option Explicit
Public Function db_backup()
Dim sourceFile As String, destinationFile As String
Dim aFSO As Variant
Dim path As String, name As String
sourceFile = CurrentProject.QualityTest
path = CurrentProject.path
name = CurrentProject.name
destinationFile = path & "c:\users\AD36742\documents\db backups - please do not remove\" & Left(name, Len(name) - 6) & "_backup" & "_" & _
Year(Now) & "_" & Month(Now) & "_" & Day(Now) & ".accdb"
'this removes a file created on the same day
If Dir(destinationFile) <> "" Then
Kill destinationFile
End If
'this creates a backup into destination path
If Dir(destinationFile) = "" Then
Set aFSO = CreateObject("Scripting.FileSystemObject")
aFSO.CopyFile sourceFile, destinationFile, True
MsgBox "A database backup has been stored under " & destinationFile
End If
End Function
The problem is when I run this the program will give me an error saying: runtime error 438 object does not support this property or method