Hi,
I'm having a few issues getting the below backup module to work and hoped someone might be able to point me in the right direction. I've got it setup to launch on button click.
I'm getting a path not found error on the following line 'aFSO.CopyFile sourceFile, destinationFile, True'
Thanks,
Ian.
I'm having a few issues getting the below backup module to work and hoped someone might be able to point me in the right direction. I've got it setup to launch on button click.
I'm getting a path not found error on the following line 'aFSO.CopyFile sourceFile, destinationFile, True'
Thanks,
Ian.
Code:
Public Function db_backup()
Dim sourceFile As String, destinationFile As String
Dim aFSO As Variant
Dim path As String, name As String
sourceFile = CurrentProject.FullName
path = CurrentProject.path
name = CurrentProject.name
destinationFile = path & "\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