Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word File Not Found?

Status
Not open for further replies.

LJtechnical

Technical User
Aug 7, 2002
90
GB
I have the following code which should open a word document with the filename given from a field name within my form. It all seems to work properly until the code reaches the
Set wrdDoc = wrdApp.Documents.Open(strFileNm) Line, here it comes up with message saying Run Time Error 5174 File could Not be Found. Any body any ideas?
____________________________________________________________

Private Sub Command92_Click()

Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim strFileNm
Dim msg As String

Set wrdApp = New Word.Application



With FileSearch
Do
strFileNm = Forms![Front End a]!Proposal '& ".doc"
.NewSearch
.MatchTextExactly = False
.SearchSubFolders = True
.Filename = Dir(strFileNm)
.LookIn = "C:\My Documents\CMQ Database v1.0\Proposals"
.Execute
msg = "Filename not valid, Please try again:"
Loop While .FoundFiles.Count = 0
End With
Set wrdDoc = wrdApp.Documents.Open(strFileNm)
wrdApp.Visible = True
 
It would appear that the code is trying to open the document from the default word document pathand not from "C:\My Documents\CMQ Database v1.0\Proposals". You will have to pass the path and the filename into the document opening line i.e.

Set wrdDoc = wrdApp.Documents.Open(path & strFileNm)
 
Excellent work! Thanks for that. Dont suppose you have any ideas for stopping the wrdApp.Quit closing the file imediately. The command has to be there to stop the instance of winword remaining even when you close the window.

I was thinking of something like this at the end of the code:

If "word is closed"
wrdApp.Quit
EndIf
Just can't find code to do this.
 
Take it back for some reason with the code as it is this command is not required. Strange!!

Cheers saved me another afternoon of hair pulling.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top