I have a legacy VB6 application that uploads file attachments to a database BLOB field. It works fine unless a user has the file open.
I tried creating a copy of th
Answering my own question:
Based on this article, the answer that worked for me is described below.
1 - Add this declaration to the VB file:
Declare Function apiCopyFile Lib "kernel32" Alias "CopyFileA" _
(ByVal lpExistingFileName As String, _
ByVal lpNewFileName As String, _
ByVal bFailIfExists As Long) As Long
2 - Create a little wrapper for that function, like so:
Sub CopyFileEvenIfOpen(SourceFile As String, DestFile As String)
Dim Result As Long
If Dir(SourceFile) = "" Then
MsgBox Chr(34) & SourceFile & Chr(34) & " is not valid file name."
Else
Result = apiCopyFile(SourceFile, DestFile, False)
End If
End Sub
3 - Replace my previous call to FileCopy with this:
CopyFileEvenIfOpen sourceFile, tempFile