Filecopy won't copy open database...what will

  • Thread starter Thread starter Mark Schirle
  • Start date Start date
M

Mark Schirle

If I use filecopy to copy a database that is open in vba code I get an
error. But if I use Windows Explorer and drag and drop the same open
database it copies fine. So the question is "Is there a way to copy an
open database thru vba code without getting an error?"
TIA
 
1) While the database is open, there may be cached data, so the
file not be correct.
2) But you can use 'copy' from the command shell, or code like this:
-------------------
Sub copyfile(ByVal vname1, ByVal vname2)
'98/02/22
On Error GoTo err_copyf

Dim ifile1 As Integer
Dim ifile2 As Integer
Dim mystring As String

ifile1 = FreeFile

5550 Open vname1 For Binary Access Read Shared As ifile1 '98/02/22
ifile2 = FreeFile
5555 Open vname2 For Binary Access Write As ifile2

5560 mystring = String$(16000, " ")
5570 Do
5580 Get #ifile1, , mystring
5590 Put #ifile2, , mystring
5600 Loop Until EOF(ifile1)

Close
Exit Sub
err_copyf:
MsgBox Err.Description & vbCrLf & vname1 & vbCrLf & vname2, vbExclamation,
Str$(Erl)
Close
Exit Sub


End Sub
 
Mark

Heed the warning in davids post!

But if you must I belive that the file scripting object CopyFile function
will do what you want. Something like:

Dim objFs as object

set objFs = CreateObject("Scripting.FileSystemObject")
objFs.CopyFile strSource, strDest
Set objFs = nothing

Wrap all of that up in some good error handling and you should be good to
go.

Ron W
 
Back
Top