Using VB6, how do I copy an ACCESS 2003 mdb file from another computer to my computer, when the mdb file is opened by another person?
+4
A:
If you try to use the FileCopy statement on a currently open file, an error occurs. However, the FileSystemObject's CopyFile function doesn't have a problem with it, so use that instead. First, you will need to add a reference to the Microsoft Scripting Runtime (on the Project->References... menu). Then you can do this:
Dim fso As New FileSystemObject
fso.CopyFile "\\someOtherComputer\share\foo.mdb", "C:\foo.mdb"
raven
2009-07-16 19:26:20
+1
A:
You can also use the Windows API
Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" _
(ByVal lpExistingFileName As String, ByVal lpNewFileName As String, _
ByVal bFailIfExists As Long) As Long
Public Function CopyFileA(OldFileName As String, NewFileName As String) As Boolean
On Error Resume Next
If CopyFile(OldFileName, NewFileName, False) <> 1 Then
MsgBox "Error copying file", vbExclamation,
Else
CopyFileA = True
End If
End Function
alweisenborn
2009-08-28 00:39:01
Yes, but it is much easier using the FileSystemObject, and once you have started using that, you will see that there are also many other useful file system methods on that object....
awe
2009-08-28 05:17:35