Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Backup to a specific location

Status
Not open for further replies.

McLiguori

Technical User
Mar 27, 2003
90
IT
I have a database in which I have included a button to backup the database using the following code:

Private Sub Comand58_Click()
filename = "c:\Database\Journals.mdb"
Set fso = CreateObject("Scripting.FileSystemObject")
Set mainfile = fso.GetFile(filename)
mainfile.Copy "I:\BACKUP of Journals" & " " & Format(Date, "yyyy-mm-dd") & " [" & Format(Time, "hh.mm.ss") & "]" & ".mdb"
End Sub

The button and backup work fine. However, the target folder must be programmed in for each different user.

Is there a way I can make the button give the user a choice as to the location desired for the backup. The backup file name and time and date format can remain constant.

The built in backup function in 2007 does this. How can I programatically emulate that action?

Thank you for your help.

McLigs
 
Yep, you can use the Browse Folder dialog and allow the user to select one:

<
Alternatively you could use an InputBox and have the user type the file path.

The first option is a better one, IMHO, as it ensures paths are not mistyped.

Ed Metcalfe.

Please do not feed the trolls.....
 
Thank you very much Ed2020. As I have limited knowledge of Access coding, can you tell me where I would insert the code given in the link you provided.

Where would it go in relation to the code I provided in my original post? Does my code need to be included somewhere in the code provided in the link?

Thanks again.
 
You're welcome.

To use this in your code, first create a new module in your database and paste in the code from the page I have linked to.

Then amend the code you already have to:

Code:
Private Sub Comand58_Click()
filename = "c:\Database\Journals.mdb"
Set fso = CreateObject("Scripting.FileSystemObject")
Set mainfile = fso.GetFile(filename)
mainfile.Copy BrowseForFolder("Select destination for backup...") & "\BACKUP of Journals" & " " & Format(Date, "yyyy-mm-dd") & " [" & Format(Time, "hh.mm.ss") & "]" & ".mdb"
End Sub

HTH,

Ed Metcalfe.

Please do not feed the trolls.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top