PMFJI,
Without knowing the sub name or how the variables are declared, I created a test sub.
Code:
Option Compare Database
Option Explicit
Private Sub btnDupeFile_Click()
Dim sSourceFile As String
Dim sDestinationFile As String
Dim sFileExists As String
sSourceFile = "D:\Forum\Misc\TestFile.ini"
sDestinationFile = "D:\Forum\Misc\TestFile" & Me.ID_TRADE & ".ini"
sFileExists = Dir(sDestinationFile)
Debug.Print sSourceFile
Debug.Print sDestinationFile
Debug.Print "FileExists = " & sFileExists
' check if file already exists
If Len(Trim(sFileExists)) > 0 Then
MsgBox "File Already exists"
Else
FileCopy sSourceFile, sDestinationFile
End If
End Sub
On first run, these are the debug prints:
D:\Forum\Misc\desktop.ini
D:\Forum\Misc\desktop12345.ini
FileExists =
And the file was copied with a new name.
Then I ran it again. These are the debug prints:
D:\Forum\Misc\desktop.ini
D:\Forum\Misc\desktop12345.ini
FileExists = desktop12345.ini
Since the file already exists, the code skips creating the file again. Note that if the check to see if the file exists is not done, the file will overwrite the existing file without any notice.
I also tried a text file "MTZTools.txt" and the copy was created ("MTZTools12345.txt").
Maybe there is some corruption??