Hi All,
I need help setting a backup button.
I've found the thread :
https://access-programmers.co.uk/forums/showthread.php?t=199405
Working step by step, I created a from (frm_Backup). I have a problem with the code of the backup button :
After reading the thread I linked, I created a folder "Data" and placed my database in it. When I test the button and click on the backup button I get the following error :
Run-time error '76' : Path not found
When I debug the code the following line is underlined in yellow :
In addition to the error message I get, the folder "Backups" is still created but remains empty.
I've attached a sample of the backup I'e done.
Thank you for your help,
Mat
I need help setting a backup button.
I've found the thread :
https://access-programmers.co.uk/forums/showthread.php?t=199405
Working step by step, I created a from (frm_Backup). I have a problem with the code of the backup button :
Code:
Private Sub Button_Backup_Click()
Dim str As String
Dim buf As String
Dim MD_Date As Variant
Dim fs As Object
Dim source As String
Const conPATH_FILE_ACCESS_ERROR = 75
On Error GoTo Backup_Button_Backup
'buf = Back Up Folder
'buf is created if it does not exist
'CurrentProject.Path = the path that the FE is located
buf = CurrentProject.Path & "\Backups\"
MkDir buf
Resume Backup_Button_Backup
Backup_Button_Backup:
'Use yyyy-mm-dd hh-mm-ss as folder name. Change as needed.
MD_Date = Format(Date, "yyyy-mm-dd ") & Format(Time, "hh-mm-ss")
str = CurrentProject.Path & "\Backups\" & MD_Date
'Source = where the data is stored
source = CurrentProject.Path & "\Data\"
MkDir str
Set fs = CreateObject("Scripting.FileSystemObject")
'Change the file extension as needed
fs.CopyFile source & "*.accdb", str
Set fs = Nothing
MsgBox "Data backup at " & vbCrLf & MD_Date & vbCrLf & "successfully!", _
vbInformation, "Backup Successful"
Exit_Button_Backup:
Exit Sub
Err_Button_Backup:
If Err.Number = conPATH_FILE_ACCESS_ERROR Then
MsgBox "The following Path, " & str & ", already exists or there was an Error " & _
"accessing it!", vbExclamation, "Path/File Access Error"
Else
MsgBox Err.Description, vbExclamation, "Error Creating " & str
End If
Resume Exit_Button_Backup
End Sub
After reading the thread I linked, I created a folder "Data" and placed my database in it. When I test the button and click on the backup button I get the following error :
Run-time error '76' : Path not found
When I debug the code the following line is underlined in yellow :
Code:
fs.CopyFile source & "*.accdb", str
In addition to the error message I get, the folder "Backups" is still created but remains empty.
I've attached a sample of the backup I'e done.
Thank you for your help,
Mat