Strange problem with filesearch...help

R

reesmacleod

Hi,

I have found a very strange and dificullt problem to overcome in th
filesearch.

When a user tries to create a new workbook file in my program, it wil
first check to see if the file already exists in the working folder
for the application, and if it does, then it pops up a message sayin
that it already exists so they cant create it.

Ok, I thought it was perfect, until they discovered that if the have
workbook named for example, week49-555EWO.xls, and they try to create
file named week49-555.xls, the file search says that the file nam
already exists!! So obviously Filesearch is using some sort of strin
search that looks for any characters that exist within that fil
name...for instance, if I try to create a new file calle
week49-55.xls, it will also say it exists!! or any combination up t
the last character of the name, week49-555EWO. It is ver
frusterating, and I can't think of how to get around it . I have, o
course, set the .MatchTextExactly to true, but that doesn't seem t
make any difference.

Here is my code


Set objFileSearch = Application.FileSearch
With objFileSearch
.NewSearch
.LookIn = startSearchDirectory
.SearchSubFolders = True
.filename = holdThisFileName
.MatchTextExactly = True
If .Execute > 0 Then
holdName = .filename
MsgBox "There is already a file named " & holdThisFileName
", in the system. If you are unsure how to proceed then please spea
to your supervisor.", vbOKOnly, "File Conflict..."
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Exit Sub
End If
End With


Any ideas, anyone?

Thanks,

Ree
 
R

reesmacleod

The line

holdName = .filename

is not supposed to be there...was some wrong code

Thx
 
T

Tom Ogilvy

Set objFileSearch = Application.FileSearch
With objFileSearch
.NewSearch
.LookIn = startSearchDirectory
.SearchSubFolders = True
.filename = holdThisFileName
'MatchTextExactly = True
If .Execute > 0 Then
for i = 1 to .foundfiles.count
if Ucase(holdThisFileName) = Ucase(.filename(i)) then

MsgBox "There is already a file named " & holdThisFileName &
", in the system. If you are unsure how to proceed then please speak
to your supervisor.", vbOKOnly, "File Conflict..."
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Exit Sub
end if
Next
End If
End With

--
Regards,
Tom Ogilvy


reesmacleod said:
The line

holdName = .filename

is not supposed to be there...was some wrong code

Thx


------------------------------------------------



~~Now Available: Financial Statements.xls, a step by step guide to
creating financial statements
 
R

reesmacleod

Thanks again Tom. You are Invaluable.

I came up with a similar solution not too long after, and as I think on
it I am surprised about that behaviour. Is it a bug? Shouldn't
..MatchTextExactly only find entire string matches and not partial
matches?

Rees
 
T

Tom Ogilvy

MatchTextExactly refers to doing a search for text contained in a file, not
the name.

--
Regards,
Tom Ogilvy


reesmacleod said:
Thanks again Tom. You are Invaluable.

I came up with a similar solution not too long after, and as I think on
it I am surprised about that behaviour. Is it a bug? Shouldn't
MatchTextExactly only find entire string matches and not partial
matches?

Rees


------------------------------------------------



~~Now Available: Financial Statements.xls, a step by step guide to
creating financial statements
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top