Problem with file searching

  • Thread starter Thread starter David Howlett
  • Start date Start date
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?
 
David Howlett said:
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?

Did you see my reply to your message "Problem with Application.filesearch"
in <microsoft.public.access> on August 4th?
 
No I didn't. In fact I looked for my original message, couldn't find it, and
re-posted.
Could you tell me what your original reply was?
 
Here's a link to the original message:


And here's a pointer to the archive of it on Google Groups:


http://groups.google.com/groups?safe=images&ie=UTF-8&oe=UTF-8&as_umsgid=uCZc
(e-mail address removed)&lr=&hl=en

Beware: the above link may be broken by the newsreader's line-wrapping, but
it was entered all on one line.

I heartily recommend Google Groups ( http://groups.google.com ), especially
their Advanced Groups Search page (
http://groups.google.com/advanced_group_search?hl=en ) when you want to find
a message you can't seem to turn up.
 
Back
Top