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!

Specifying word doc to open from access

Status
Not open for further replies.

LJtechnical

Technical User
Aug 7, 2002
90
GB
I am trying to make a button open a word doc according to the string contents of the field "Proposal". My attempt to pass the file name is not working and niether is my if string is null loop. Any body got any tips? Code Below

Cheers
___________________________________________________________
Private Sub Command92_Click()
Dim wdApp As Word.Application
Dim strFile As String
Set wdApp = New Word.Application
wdApp.Visible = True
wdApp.WindowState = wdWindowStateMaximize

strFile = Forms![Front End a]!Proposal
If IsNull(strFile) Then
MsgBox "There is no proposal available for this programme currently. Please contact our sales department for more information"
Resume ErrorHandlerExit
End If

wdApp.Documents.Open FileName:="CMQ Database v1.0\Proposals\strFile.doc", ConfirmConversions:= _
False, ReadOnly:=True, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto
ErrorHandlerExit:
End Sub
 
I would check for a zero length string rather than using isNull, and to take it a step further you should check to make certain that not only is there a value present but it represents a valid word document. Perhaps you might want to try something like this:

Sub openWordDoc()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim strFileNm
Dim msg As String

Set wrdApp = New Word.Application

msg = "Enter word filename:"

With FileSearch
Do
strFileNm = InputBox(msg, "Get file", "")
.NewSearch
.MatchTextExactly = True
.SearchSubFolders = False
.Filename = Dir(strFileNm)
.LookIn = Left(strFileNm, Len(strFileNm) - Len(.Filename))
.Execute
msg = "Filename not valid, Please try again:"
Loop While .FoundFiles.Count = 0
End With
Set wrdDoc = wrdApp.Documents.Open(strFileNm)
wrdApp.Visible = True
'wrdApp.Quit
'Set wrdDoc = Nothing
'Set wrdApp = Nothing
End Sub
 
Cheers seems to go a step further than my effort, I have modified it to obtain file name from text box in form. But i get error cant find file. I have tried placing file in same folder but to no avail.
Is the directory set to look just in project folder?

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

'msg = "Enter word filename:"

With FileSearch
Do
strFileNm = Forms![Front End a]!Proposal & ".doc" 'InputBox(msg, "Get file", "")
.NewSearch
.MatchTextExactly = True
.SearchSubFolders = True
.Filename = Dir(strFileNm)
.LookIn = Left(strFileNm, Len(strFileNm) - Len(.Filename))
.Execute
msg = "Filename not valid, Please try again:"
Loop While .FoundFiles.Count = 0
End With
Set wrdDoc = wrdApp.Documents.Open(strFileNm)
wrdApp.Visible = True
'wrdApp.Quit
'Set wrdDoc = Nothing
'Set wrdApp = Nothing

End Sub
 
What are you entering into the form, the full path for the file, or are you just entering a filename and want to look in: a. the current directory; b. a specific directory?

If you want to continue just entering the filename and not the path you can change the .lookin in to .lookin = curdir() or you can type in the path to the specific folder that the file should be in .lookin = "c:\projects\worddocs\"

If you are already entering in the full path and the filesearch is not working I do not have any suggestions at the moment.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top