CurrentProject.Path (1 Viewer)

Portucale

Registered User.
Local time
Today, 12:40
Joined
Sep 7, 2012
Messages
32
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.

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
 

pr2-eugin

Super Moderator
Local time
Today, 12:40
Joined
Nov 30, 2011
Messages
8,494
Would love to help if you tell what you want.. You said you need to change the path, but to where?
 

Portucale

Registered User.
Local time
Today, 12:40
Joined
Sep 7, 2012
Messages
32
The current path is:
Y:\Sales Analysis\Analysis Team Folders\Service Team\Universe
I would like something like:
Y:\Sales Analysis\Analysis Team Folders\Service Team\Universe\Backups

Thanks,
 

pr2-eugin

Super Moderator
Local time
Today, 12:40
Joined
Nov 30, 2011
Messages
8,494
After the Path just add the word Backup..
Code:
sFile = CurrentProject.Path & "[COLOR=Red][B]\Backup[/B][/COLOR]\" & "DB1_Backup-" & "-" & Format(Date, "m-d-yy") & ".accdb"
Make sure the path exists before you run the procedure.. In other words, make sure you create the Folder Backup in the CurrentProject path before you run this code..
 

Portucale

Registered User.
Local time
Today, 12:40
Joined
Sep 7, 2012
Messages
32
Feel dumb... :banghead:

Tried so many different ways and the answer was so simple... Well when you know.

Thanks for the help, forever grateful

:)
 

Users who are viewing this thread

Top Bottom