Hello,
I am using the code below and have the following problems...
If the file exists and I say I don't want to overwrite the code continues to execute.
Also the files are copying but not retaining their correct file extentions.
I am just learning coding so I would much appreciate and advice in regard to modifying the code to make it better in any areas.
Me.txt_File_Selected is a text box on my form containing the full source path and file name i.e. c:\temp\dog.jpg
Me.txtfile is a text box on my form containing the destination path and file name i.e. c:\temp\dog
Many thanks Mark
I am using the code below and have the following problems...
If the file exists and I say I don't want to overwrite the code continues to execute.
Also the files are copying but not retaining their correct file extentions.
I am just learning coding so I would much appreciate and advice in regard to modifying the code to make it better in any areas.
Me.txt_File_Selected is a text box on my form containing the full source path and file name i.e. c:\temp\dog.jpg
Me.txtfile is a text box on my form containing the destination path and file name i.e. c:\temp\dog
Many thanks Mark
Code:
Dim fso As Object
Dim sourceFile As String
Dim targetFile As String
Dim answer As Boolean
Set fso = CreateObject("Scripting.FileSystemObject")
sourceFile = Me.txt_File_Selected
targetFile = Me.txtfile
If fso.FileExists(sourceFile) = False Then
MsgBox "The source file can not be found - please search for the file again"
Exit Sub
End If
If fso.FileExists(targetFile) = True Then
answer = MsgBox("File already exists in this location. " _
& "Are you sure you want to continue? If you continue " _
& "the file at destination will be over written!", _
vbInformation + vbYesNo)
If answer = vbNo Then
Exit Sub
End If
End If
fso.CopyFile sourceFile, targetFile
Set fso = Nothing
MsgBox "The file has been Added"