Can't view a word document.

  • Thread starter Thread starter Shipp
  • Start date Start date
S

Shipp

I have the following code in a module. When I execute the
code Word is loaded and is visible. However, the document
that is declared in strDOC does not load up automatically.
Any help would be appreciated.

Private Sub btnWord_Click()

On Error GoTo Err_btnWord_Click

Dim strDir As String
Dim strDoc As String
Dim strTyp As String
Dim strFul As String
Dim objWord As Word.Document

strDir = Forms!frmConHdr!sfrmDocuments.Form.Directory
strDoc = Forms!frmConHdr!sfrmDocuments.Form.FileName
strTyp = Forms!frmConHdr!sfrmDocuments.Form.cboType
strFul = strDir & strDoc & "." & strTyp

Set objWord = GetObject(strFul)
objWord.Application.Visible = True

Exit_btnWord_Click:
Exit Sub

Err_btnWord_Click:
MsgBox Err.Description
Resume Exit_btnWord_Click

End Sub
 
Why would you *expect* the document in strDOC to be loaded automatically?
How would Word possibly know that you wanted that to happen? How would it
know that strDOC held the document name, and not strDir, or strTyp?

You have to *tell* Word to open the document, by using the appropriate Word
method; OPEN, I guess - I do not have Word here to check.

Something like:
Set objWord = GetObject(strFul)
objWord.Application.Visible = True
objWord.Open strDOC

HTH,
TC
 
Hi - this works :

Private Sub Command21_Click()
Dim strCmd As String

strCmd = """C:\Program Files\Common Files\Microsoft
Shared\PhotoEd\Photoed.exe"""
strCmd = strCmd & """" & Me![FilePathName] & """"
Shell strCmd
End Sub

Substitute winword.exe for PhotoEd.exe. FilePathName
refers to my table field which stores the file and
pathname (duh). Click on a command button with this code
in your on-click and bingo

Matthew
 
Back
Top