Hi,
I have a code which creates a backup of my project on open as a AutoExec, but it creates the Backup in the current path, I would like to change the current path to a different one.
Any help is very much appreciated
I have a code which creates a backup of my project on open as a AutoExec, but it creates the Backup in the current path, I would like to change the current path to a different one.
Code:
Sub Backup()
Dim dTime As Date
Dim sFile As String, oDB As DAO.Database
Dim oTD As TableDef
On Error Resume Next
dTime = InputBox("Create a backup at", , Time + TimeValue("00:02:00"))
If Err.Number <> 0 Then Exit Sub
Do Until Time = dTime
DoEvents
Loop
'MsgBox "Time to create a backup"
sFile = CurrentProject.Path & "\" & "DB1_Backup-" & "-" & Format(Date, "m-d-yy") & ".accdb"
If Dir(sFile) <> "" Then Kill sFile
Set oDB = DBEngine.Workspaces(0).CreateDatabase(sFile, dbLangGeneral)
oDB.Close
DoCmd.Hourglass True
For Each oTD In CurrentDb.TableDefs
'to copy also the system tables that MS creates, if not required remove line
If Left(oTD.Name, 4) <> "MSys" Then
DoCmd.CopyObject sFile, , acTable, oTD.Name
End If
DoCmd.Hourglass False
Next oTD
MsgBox "Backup is stored in the same folder"
End Sub
Any help is very much appreciated