SachAccess
Active member
- Local time
- Tomorrow, 04:54
- Joined
- Nov 22, 2021
- Messages
- 391
Hi,
I am using below code to create back-up of my MS Access file.
I have changed the original names however, have checked the actual path name manually and it is accessible.
This code was written yesterday. It was working fine till one our ago. In fact I have created multiple back-ups files with this code.
I tried to change this code to function and get it run via AutoExec, it did not work for me due to some reasons.
Hence I reverted from Function to Sub. And thought that I will assign a VBA Sub to a button for this.
However, when am running the same code now, am getting an error at FileCopy SourceFile, DestinationFile saying permission denied.
I am not able to understand the reason. I have not changed anything in the code. It was working fine. Then why this error.
Can anyone please help me in this.
I am using below code to create back-up of my MS Access file.
I have changed the original names however, have checked the actual path name manually and it is accessible.
This code was written yesterday. It was working fine till one our ago. In fact I have created multiple back-ups files with this code.
I tried to change this code to function and get it run via AutoExec, it did not work for me due to some reasons.
Hence I reverted from Function to Sub. And thought that I will assign a VBA Sub to a button for this.
However, when am running the same code now, am getting an error at FileCopy SourceFile, DestinationFile saying permission denied.
I am not able to understand the reason. I have not changed anything in the code. It was working fine. Then why this error.
Can anyone please help me in this.
Code:
Sub BackUp()
Dim SourceFile, DestinationFile
Dim MyFileName As Variant
SourceFile = "M:\ MyActualPathHere \MyActualFileName.accdb" ' Define source file name.
MyFileName = Day(Now)
MyFileName = MyFileName & "-" & Month(Now)
MyFileName = MyFileName & "-" & Year(Now)
MyFileName = MyFileName & "-" & Hour(Now)
MyFileName = MyFileName & "-" & Minute(Now)
MyFileName = MyFileName & "-" & Second(Now)
MyFileName = "BackUpFile" & "-" & MyFileName & "-" & Trim(UCase(Environ("UserName"))) & ".accdb"
DestinationFile = "M:\MyActualPathHere\ " & MyFileName
FileCopy SourceFile, DestinationFile ' Copy source to target.
End Sub