Search folder for string and open file is match found

  • Thread starter Thread starter Maver1ck666
  • Start date Start date
M

Maver1ck666

Hi all,

I have a database that contains over 2000 external system errors and I have
a folder with a snapshot of each said errors.

What I am trying to do is to add a cmd button to search through the network
folder and IF it finds a match, to open it else display a msg box.

The only problem is, the file can either be a .doc or .msg (but only one of
those two types).

Does anyone have any code or suggestions of sites to look at please?

Thanks for the help!

Ben
 
Here is a basic example of a way that will work for you. You might need to
modify it to meet your needs:

Public Function FindFiles(MatchFileName As String) As Boolean
Dim strFileName As String

strFileName = Dir(MatchDir & "c:\documents and settings\daveh\my
documents\*.*")
Do While strFileName <> vbNullString
If strFileName = MatchFileName Then
FindFiles = True
Exit Function
End If
strFileName = Dir
Loop

FindFiles = False

End Function
 
Thanks for that Klatuu.

I have been trying to work out my own code using snippets of other peoples
and have come up with this so far:

Dim vItem As Variant
Dim db As DAO.Database
Dim strPath As String
Dim strRepName As String

strPath = "P:\E\ERR_REPS\Examples\"
strRepName = Me.Str_ReportName

Set db = CurrentDb
With Application.FileSearch

..FileName = strRepName
..LookIn = "P:\E\ERR_REPS\Examples"
..SearchSubFolders = True
..Execute

For Each vItem In .FoundFiles

If vItem = strPath & strRepName & ".doc" Then

Dim oApp As Object
Dim doc As Object

Set oApp = CreateObject("Word.Application")
oApp.Visible = True

Set doc = oApp.Documents.Open(strPath & strRepName & ".doc")

Else

If vItem = strPath & strRepName & ".msg" Then





Else

End If

End If

Next vItem

End With

Set db = Nothing

the only problem is I cannot seem to find a way to open outlook messages
that have been saved in a folder too (so Outlook doesn't need to open).

Any ideas please?
 
Instead of creating objects for each type of file to open, why not simply use
the Application.FollowHyperlink Method which will open any file using the
default program associated with it.
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.
 
Thanks Daniel for that. How would that work though if I dont know the
extension of the file I am trying to open? Or have I misunderstood your
comment?
 
Ignore my last post, I sussed out what you meant.

The Application.FollowHyperlink method works beautifully now but!!! :) I get
a dialogue box appear when opening outlook items saying please be careful, is
it a trustworthy source etc. Is there a way to prevent that message from
opening?
 
Back
Top