D
David Howlett
I have some code that is supposed to copy files from one folder to another.
However, on different days the files change. For example:
On day 1, the inbox folder contains Analyst3.mdb, Analyst5.mdb and
Analyst9.mdb
On day 2, the inbox folder contains Analyst4.mdb, Analyst7.mdb and
Analyst11.mdb
Here is the code:
Sub CopyNetworkInBox(InboxPath, outboxPath)
Dim x
Dim sourcefile
x = 1
notification = False
Do While x <= 20
sourcefile = "analyst" & x & ".mdb"
With Application.FileSearch
.NewSearch
.LookIn = InboxPath
.SearchSubFolders = False
.FileName = sourcefile
.MatchTextExactly = True
If .Execute > 0 Then
copyNetInboxFile InboxPath & sourcefile, outboxPath
Kill InboxPath & sourcefile
Else
Exit Do
End If
End With
x = x + 1
Loop
End Sub
The problem is that if there is a file named 'Analyst10.mdb' this code
matches the very first time through the loop (x=1,
sourcefile='Analyst1.mdb'). I get errors in the subroutine because it is
trying to copy a file named 'Analyst1.mdb' which doesn't exists.
How do I get this code to match only if the exact filename is found?
However, on different days the files change. For example:
On day 1, the inbox folder contains Analyst3.mdb, Analyst5.mdb and
Analyst9.mdb
On day 2, the inbox folder contains Analyst4.mdb, Analyst7.mdb and
Analyst11.mdb
Here is the code:
Sub CopyNetworkInBox(InboxPath, outboxPath)
Dim x
Dim sourcefile
x = 1
notification = False
Do While x <= 20
sourcefile = "analyst" & x & ".mdb"
With Application.FileSearch
.NewSearch
.LookIn = InboxPath
.SearchSubFolders = False
.FileName = sourcefile
.MatchTextExactly = True
If .Execute > 0 Then
copyNetInboxFile InboxPath & sourcefile, outboxPath
Kill InboxPath & sourcefile
Else
Exit Do
End If
End With
x = x + 1
Loop
End Sub
The problem is that if there is a file named 'Analyst10.mdb' this code
matches the very first time through the loop (x=1,
sourcefile='Analyst1.mdb'). I get errors in the subroutine because it is
trying to copy a file named 'Analyst1.mdb' which doesn't exists.
How do I get this code to match only if the exact filename is found?