Make Copy Of Current Database File

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to make a copy of the current database file? I tried FileCopy
and it raises an error.

Thanks!
 
Are you inside of the application?

If yes, then I would suggest that you use the compact feature.

The compact feature will ensure that no tables are open, and no other users
(or multiple copies) are running. Then, and only then will the copy proceed.
Further, since it is a compacted copy, and your will find that the size is
as small as it can/should be.

The code to do this is like:

Public Function MyCompactDB(strToFile As String) As Boolean

' compact to a db called "bak" in local dir...

dim strFromFile as string

On Error GoTo CompactDB_Error

strFromFile = currentdb.Name

' If Len(Dir(strToFile)) > 0 Then
' Kill strToFile
' End If

DBEngine.CompactDatabase strFromFile, strToFile


MyCompactDB = True

Exit Function



CompactDB_Error:


If Err.Number = 3356 Then

MsgBox "There are other users in the Data File" & vbCrLf & _
"(or you have more then one copy of program running)" & vbCrLf
& _
vbCrLf & _
"All other users must exit before you can complete this data" &
vbCrLf & _
"Maintenace on your data file" & vbCrLf & vbCrLf & _
"Please try again later", vbExclamation, AppName
Else

MsgBox "Unable to compact file" & vbCrLf & vbCrLf & _
"Error " & Err.Number & " (" & Err.Description & ")",
vbCritical, AppName


End If


End Function


To use, then you then go

if CompactMyDB = true then

' copy ok....

else

' copy was not ok

end if
 
Yes, I am inside the current database.

I tried your CompactDatabase function and I got the 3356 error.

The Help file for the CompactDatabase method says --
"Copies and compacts a closed database....". The currentdatabase is open so
it looks like the CompactDatabase method will not work. Other ideas?

Thanks, for responding!!
 

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

Back
Top