Bill Patten
bill_Patten at earthlink.net
Thu Feb 23 12:55:49 CST 2006
Here is routine that I use.
Declare Function apiCopyFile Lib "kernel32" Alias "CopyFileA" _
(ByVal lpExistingFileName As String, _
ByVal lpNewFileName As String, _
ByVal bFailIfExists As Long) As Long
Declare Function SetFileAttributes Lib "kernel32" Alias
"SetFileAttributesA" _
(ByVal lpFileName As String, ByVal dwFileAttributes As Long) As Long
Function BPCopyFile(SourceFile As String, DestFile As String, Optional
intReadOnly As Integer) As Boolean
On Error GoTo Err_BPCopyFile
'----------------------------------------------------------------------------
' Purpose: Copy a file on disk from one location to another and on request
change to or from readonly
' BPcopyfile "c:\dog.oub, c:\cat.mdb , optional 1 = readonly 2 = not
readonly
' though this function will copy any files (open ones too) it was designed
to copy a
' file from a CD, rename it and then make sure it is not read only
' By: Bill Patten, BPCS
' Date: 9/16/2003 8:41:58 PM
' Mods:
'----------------------------------------------------------------------------
Const FILE_ATTRIBUTE_NORMAL = 128
Const FILE_ATTRIBUTE_READONLY = 1
Dim Result As Long
BPCopyFile = False 'Assume it wont work
If Dir(DestFile) <> "" Then ' desination file exist so kill it
'Just in case it is readonly and would not delete
Result = SetFileAttributes(DestFile, FILE_ATTRIBUTE_NORMAL)
Kill (DestFile)
End If
If Dir(SourceFile) = "" Then
MsgBox Chr(34) & SourceFile & Chr(34) & _
" is not valid file name."
Exit Function
Else
Result = apiCopyFile(SourceFile, DestFile, False)
End If
If Not IsNull(intReadOnly) Then
Select Case intReadOnly
Case 1 'Make file read only
Result = SetFileAttributes(DestFile, FILE_ATTRIBUTE_READONLY)
Case 2 'remove readonly
Result = SetFileAttributes(DestFile, FILE_ATTRIBUTE_NORMAL)
End Select
End If
BPCopyFile = True
Exit_BPCopyFile:
Exit Function
Err_BPCopyFile:
MsgBox "Error " & Err.Number & ": " & Err.Description & " In Sub CopyFile
In Module modFileCopy" & vbCrLf
Resume Exit_BPCopyFile
End Function
----- Original Message -----
From: "Reuben Cummings" <reuben at gfconsultants.com>
To: "AccessD" <accessd at databaseadvisors.com>
Sent: Thursday, February 23, 2006 10:12 AM
Subject: [AccessD] Copy a file
Anyone have a system setup to copy/move files?
I want to give a client a small app that she can open, click a button and it
will copy the specified file to another specified folder elsewhere on the
network.
Reuben Cummings
GFC, LLC
812.523.1017
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com