Copy a database

S

StuJol

im currently using the following code to compact and repair my BE database on
close of my FE.

Public Sub cmdCompact_Click()
On Error GoTo Err_cmdCompact_Click


'Compact the Back-End database to a temp file.
DBEngine.CompactDatabase "C:\Program Files\Job Manager\Database\Job
Manager Database.mdb", "C:\Program Files\Job Manager\Database\Job Manager
Database Temp.mdb"

'Delete the previous backup file if it exists.
If Dir("C:\Program Files\Job Manager\Database\Job Manager Database.bak")
<> "" Then
Kill "C:\Program Files\Job Manager\Database\Job Manager Database.bak"
End If

'Rename the current database as backup and rename the temp file to the
original file name.
Name "C:\Program Files\Job Manager\Database\Job Manager Database.mdb" As
"C:\Program Files\Job Manager\Database\Job Manager Database.bak"
Name "C:\Program Files\Job Manager\Database\Job Manager Database
Temp.mdb" As "C:\Program Files\Job Manager\Database\Job Manager Database.mdb"

'Copy the backup database to the backup directory.
Name "C:\Program Files\Job Manager\Database\Job Manager Database.bak" As
"C:\Program Files\Job Manager\Database\backup\Job Manager Database " &
Format(Date, "dddd, mmm d yyyy") & ".bak"


Exit_cmdCompact_Click:
Exit Sub

Err_cmdCompact_Click:
MsgBox Err.Description & " " & Err.Number
Resume Exit_cmdCompact_Click

End Sub

this code creattes a database.bak file which im trying to copy to a new
directory but are unable to. I've used the file copy method but just keep
getting errors and i've used the rename method to try and save file in a
different directory but that doesnt work either.

Any ideas please?
 
S

strive4peace

Hi Stu,

Make sure your temp.mdb file is also deleted before you try
to overwrite it. Also, try removing the spaces from the
filename. If you want "space", use the underscore character
instead.

Job_Manager_Database_Temp.mdb

after you Kill a file, use

DoEvents

DoEvents is used to make VBA pay attention to what is
currently happening and look to see if the OS (Operating
System) has any requests.

ie: if you have a loop and want to be able to BREAK it with
CTRL-BREAK, put DoEvents into the loop

DoEvents will also update values written to a form by a
general procedure or code behind another form or report

A DoEvents is done when you use MsgBox, or are stepping
through code (since it has to pay attention to the keyboard)

It is a good way to say, "Wake Up!"
~~~~~~~~~

also, since you are renaming the db, make sure you have no
open forms, reports, quusing it.

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
R

Ron2006

How may FEs are there accessing the BE?

Are any of the FEs still attached to the BE when this is trying to
run.?

How do you know everyone is out?

Ron
 
R

Ron2006

How may FEs are there accessing the BE?

Are any of the FEs still attached to the BE when this is trying to
run.?

How do you know everyone is out?

Ron
 

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