I am trying to automatically create a back up of a database on form load. I am not having any luck with the code I have found, I am only a intermediate programmer. Does anybody have any code to create a back up on form load? Here is the code I was trying to use:
Dim strRootPath
Dim strFileName As Database
Dim objScript
Dim strPrefix
Dim strMonth
Dim strDay
Dim strHour
Dim strMinute
Dim strSource
Dim strTarget
Dim strMsg
strRootPath = "G:\ACC_ATS\MikeCRogers\Cash Card Audit (930)\Archive"
strFileName = "BackUp.mdb"
strMonth = DatePart("m", Date)
If Len(strMonth) = 1 Then strMonth = "0" & strMonth
strDay = DatePart("d", Date)
If Len(strDay) = 1 Then strDay = "0" & strDay
strYear = Right(DatePart("yyyy", Date), 2)
strHour = DatePart("h", Now())
If Len(strHour) = 1 Then strHour = "0" & strHour
strMinute = DatePart("n", Now())
If Len(strMinute) = 1 Then strMinute = "0" & strMinute
strPrefix = strMonth & strDay & strYear & "-" & strHour & strMinute & "_"
strSource = strRootPath & strFileName
strTarget = strRootPath & "Archive" & strPrefix & strFileName
Set objScript = CreateObject("Scripting.FileSystemObject")
If Not objScript.FolderExists(strRootPath & "Archive\") Then
objScript.CreateFolder (strRootPath & "Archive\")
End If
'objScript.CopyFile strSource, strTarget
Set objScript = Nothing
strMsg = "The file:" & vbCrLf & Space(5) & strPrefix & strFileName & vbCrLf & vbCrLf & "Has been created in the Archive Folder."
MsgBox strMsg, , "Finished"
Dim strRootPath
Dim strFileName As Database
Dim objScript
Dim strPrefix
Dim strMonth
Dim strDay
Dim strHour
Dim strMinute
Dim strSource
Dim strTarget
Dim strMsg
strRootPath = "G:\ACC_ATS\MikeCRogers\Cash Card Audit (930)\Archive"
strFileName = "BackUp.mdb"
strMonth = DatePart("m", Date)
If Len(strMonth) = 1 Then strMonth = "0" & strMonth
strDay = DatePart("d", Date)
If Len(strDay) = 1 Then strDay = "0" & strDay
strYear = Right(DatePart("yyyy", Date), 2)
strHour = DatePart("h", Now())
If Len(strHour) = 1 Then strHour = "0" & strHour
strMinute = DatePart("n", Now())
If Len(strMinute) = 1 Then strMinute = "0" & strMinute
strPrefix = strMonth & strDay & strYear & "-" & strHour & strMinute & "_"
strSource = strRootPath & strFileName
strTarget = strRootPath & "Archive" & strPrefix & strFileName
Set objScript = CreateObject("Scripting.FileSystemObject")
If Not objScript.FolderExists(strRootPath & "Archive\") Then
objScript.CreateFolder (strRootPath & "Archive\")
End If
'objScript.CopyFile strSource, strTarget
Set objScript = Nothing
strMsg = "The file:" & vbCrLf & Space(5) & strPrefix & strFileName & vbCrLf & vbCrLf & "Has been created in the Archive Folder."
MsgBox strMsg, , "Finished"