Backup Route Module Issues (1 Viewer)

marleyuk

Registered User.
Local time
Today, 02:03
Joined
Feb 8, 2006
Messages
54
Hi,

I'm having a few issues getting the below backup module to work and hoped someone might be able to point me in the right direction. I've got it setup to launch on button click.

I'm getting a path not found error on the following line 'aFSO.CopyFile sourceFile, destinationFile, True'

Thanks,
Ian.

Code:
Public Function db_backup()
 Dim sourceFile As String, destinationFile As String
 Dim aFSO As Variant
 Dim path As String, name As String

sourceFile = CurrentProject.FullName
 path = CurrentProject.path
 name = CurrentProject.name
 destinationFile = path & "\db backups - please do not remove\" & Left(name, Len(name) - 6) & "_backup" & "_" & _
 Year(Now) & "_" & Month(Now) & "_" & Day(Now) & ".accdb"

'this removes a file created on the same day
 If Dir(destinationFile) <> "" Then
 Kill destinationFile
 End If

'this creates a backup into destination path
 If Dir(destinationFile) = "" Then

Set aFSO = CreateObject("Scripting.FileSystemObject")
 aFSO.CopyFile sourceFile, destinationFile, True

 MsgBox "A database backup has been stored under " & destinationFile
 End If
 End Function
 

redalert

Registered User.
Local time
Today, 02:03
Joined
Oct 7, 2013
Messages
62
I got it to work after I added the following lines of code:

Code:
on error resume next
MkDir (path & "\db backups - please do not remove")

I suggest that it could not find the folder to store the backup file in.

Try not to use variables such as 'path' and 'name' as these are reserved words.

Maybe use strPath and strName instead and the prefix indicates the type of content which is informative.
 

marleyuk

Registered User.
Local time
Today, 02:03
Joined
Feb 8, 2006
Messages
54
Thank you!

This runs perfectly. This function literally copies the entire database, which is fine now as its small, but if it grows might be a bit more difficult.

Is there a way of just backing up the tables within the database?

Thanks,
Ian.
 

redalert

Registered User.
Local time
Today, 02:03
Joined
Oct 7, 2013
Messages
62
You should be using a front end (FE) and a seperate back end (BE).

The BE contains the tables only and the FE contains everything else.

A master copy of the FE is kept secure and replaced with the development copy when the development copy has been fully tested, The workin g copy is updated with the master copy. There is no need to backup the FE objects as you suggest.

The FE and BE files can be backed up using the normal backup routine that you use for your computer.

If you really want to backup the tables from your existing database then create a new database and export the tables to the new database.
 

Users who are viewing this thread

Top Bottom