Programatically copy database

  • Thread starter Thread starter Simon Morley
  • Start date Start date
S

Simon Morley

I have a back end db that I want the front end to
programatically make a copy of when the user requires it.
I need to delete the old "Back End Backup.mdb" and then
make a copy using the same name of the "Back End Live.mdb"
file. I know I could use replication, but this is over
complicating what should be a pretty simple operation.

I know there is the FileSystemObject, but I've only used
this around text files, and I'm not sure how, if it is
possible, I apply these methods to a .mdb file rather than
a .txt file. Any ideas?

Many thanks in advance,

Simon
 
I've managed to answer my own question. In case anyone is
interested, it's as easy as this:


Public Sub Test()

Dim fs As Object

Set fs = CreateObject("Scripting.FileSystemObject")

fs.copyfile CurrentProject.Path & "\Data\Back End
Live.mdb", CurrentProject.Path & "\Data\Back End
Backup.mdb", True

End Sub

Because I've set the overwrite property to True, I don't
need to delete the old file (assuming it's not read-
only). True is actually the default, but I've added it
above for illustration purposes.

Kind regards,

Simon
 
I've managed to answer my own question. In case anyone is
interested, it's as easy as this:


Public Sub Test()

Dim fs As Object

Set fs = CreateObject("Scripting.FileSystemObject")

fs.copyfile CurrentProject.Path & "\Data\Back End
Live.mdb", CurrentProject.Path & "\Data\Back End
Backup.mdb", True

End Sub

Because I've set the overwrite property to True, I don't
need to delete the old file (assuming it's not read-
only). True is actually the default, but I've added it
above for illustration purposes.

Kind regards,

Simon
 
Rather than use the FileSystemObject, which will not work if the Windows
Scripting Host is disabled (and because it is a tool used for mischief by
virus and worm authors, many System Adminstrators make sure it is disabled
on all machines under their control), why do you not use the FileCopy and
Kill statements that have been built into VBA since 16-bit Access Basic
days? Check Help.

It makes no sense to me to have to rely on some external "something" when
all the functionality you need is built right in to the product in which you
are developing.

Larry Linson
Microsoft Access MVP
 
Back
Top