Hi,
I have searched and have not been able to find anything on creating a read-only copy of a back end DB with VBA. I am creating backups of my back end file and would like to create a local read-only copy to use in the event that the regular back end is not available. If anyone has any insight, it would be greatly appreciated.
The code I am using to create the backup is:
I have searched and have not been able to find anything on creating a read-only copy of a back end DB with VBA. I am creating backups of my back end file and would like to create a local read-only copy to use in the event that the regular back end is not available. If anyone has any insight, it would be greatly appreciated.
The code I am using to create the backup is:
Code:
Public Function BackupBE()
'On Error GoTo BackupBE_Err
Dim sourceFile As String, destinationFile As String
Dim aFSO As Variant
Dim path As String, name As String
path = CurrentProject.path
name = CurrentProject.name
sourceFile = "\\OBBURTON-PC\Users\Public\Documents\" & _
"FUN Stuff\WilburBE.accdb"
destinationFile = "\\OBBURTON-PC\Users\Public\" & _
"Documents\FUN Stuff\Backups\WilburBE_Backup_" & _
Year(Now) & "-" & Month(Now) & "-" & Day(Now) & _
"_" & Hour(Now) & "-" & Minute(Now) & ".accdb"
'this removes a file created at the same time
' MsgBox destinationFile
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
BackupBE_Exit:
Exit Function
BackupBE_Err:
ErrMsg ("BackupBE")
Resume BackupBE_Exit
End Function