VBA ? re: Saving Database File

M

Marsha

First a general disclaimer - I'm not sure that i know what I'm doing;
however, I founds some VBA code that looks like it should be relatively easy
to work with. My goal is to build a module that will save a copy of my
database file, so that I'll have a backup. I'm pasting in a link to the site
with the original code and then the code as a I modified it. Again, I'm
pretty new to trying to modify and work with VBA code, so I could be making a
really stupid, lame mistake. Any help would be greatly appreciated.

http://www.mdbmakers.com/forums/showthread.php?p=15088

Adapted code:

Function fBackup()


' File(s) to copy
DataDBFile = "Scantest.mdb"
DataDBPath = "Z:\Registry\Reg Scan Files\REGISTRY DATABASE FILES\2006
Registry Database\"

' Main directory to store backups
BackupDir = "Z:\Registry\Reg Scan Files\REGISTRY DATABASE FILES\2008 Back Up
Files"

' Subdirectory of above for actual file
NewDirName = Year(Date) & "." & Month(Date) & "." & Day(Date)

' Create File System object
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

' Check if backup folder exists
If Not fso.FolderExists(BackupDir) Then
fso.CreateFolder (BackupDir)
End If

' Create new folder for current backup
Dim fld
Set fld = fso.CreateFolder(BackupDir & "\" & NewDirName)

' Copy file(s)
fso.CopyFile DataDBFile, fso.BuildPath(fld, DataDBFile & ".BACKUP") [THIS IS
WHERE I'M GETTING THE DEBUG ERROR I'M NOT SURE IF MY PATH IS NOT WRITTEN
CORRECTLY ABOVE OR WHAT, THE CODE SEEMS TO WORK FINE UP TO HERE, IT CREATES A
NEW FOLDER ON THE DRIVE AND EVERYTHING]

End Function
 
M

Marsha

YES!!!!!! That worked and was sooo much easier thanks for your help, I've
been trying to find code to do this for days :)

biganthony via AccessMonster.com said:
Marsha,

Could you use this:

Public Function BackupDatabase()
CommandBars("Menu Bar").Controls("Tools"). _
Controls("Database utilities").Controls("Back up database..."). _
accDoDefaultAction
End Function

I have it in a module and call the function from a menu and it backs up the
database and allows you to select the folder where it is to be saved.

Anthony
First a general disclaimer - I'm not sure that i know what I'm doing;
however, I founds some VBA code that looks like it should be relatively easy
to work with. My goal is to build a module that will save a copy of my
database file, so that I'll have a backup. I'm pasting in a link to the site
with the original code and then the code as a I modified it. Again, I'm
pretty new to trying to modify and work with VBA code, so I could be making a
really stupid, lame mistake. Any help would be greatly appreciated.

http://www.mdbmakers.com/forums/showthread.php?p=15088

Adapted code:

Function fBackup()

' File(s) to copy
DataDBFile = "Scantest.mdb"
DataDBPath = "Z:\Registry\Reg Scan Files\REGISTRY DATABASE FILES\2006
Registry Database\"

' Main directory to store backups
BackupDir = "Z:\Registry\Reg Scan Files\REGISTRY DATABASE FILES\2008 Back Up
Files"

' Subdirectory of above for actual file
NewDirName = Year(Date) & "." & Month(Date) & "." & Day(Date)

' Create File System object
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

' Check if backup folder exists
If Not fso.FolderExists(BackupDir) Then
fso.CreateFolder (BackupDir)
End If

' Create new folder for current backup
Dim fld
Set fld = fso.CreateFolder(BackupDir & "\" & NewDirName)

' Copy file(s)
fso.CopyFile DataDBFile, fso.BuildPath(fld, DataDBFile & ".BACKUP") [THIS IS
WHERE I'M GETTING THE DEBUG ERROR I'M NOT SURE IF MY PATH IS NOT WRITTEN
CORRECTLY ABOVE OR WHAT, THE CODE SEEMS TO WORK FINE UP TO HERE, IT CREATES A
NEW FOLDER ON THE DRIVE AND EVERYTHING]

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top