K
Kevin B
Hopefully someone has had this issue and can help, but I’m stumped at this
point.
Both Word and Access are Office 2003 applications.
I’m launching Word from an Access form and the application launches just
fine, using either GetObject if there’s an active session or CreateObject it
there isn’t.
If I open a document I do not have any problems, however, when I attempt to
use a template I get an error 5151 “Word was unable to read this document.
It may be corrupt.â€
If I launch Word manually the template opens just fine, but the code cannot
seem to do this. I’ve gotten a very functional error routine going, so not
all is lost, but my original goal ass not been met.
All variables in the code sample below have been explicitly declared and
when I step through the code using watch the string variables have all the
correct values
----------------------------------------------------------------------------------
strPath = DocPath() 'UDF
strTemplate = conAppPath & conDocDot
strDocName = frm.txtPlogID.Value & ".doc"
Set objWord = GetObject(, "Word.Application")
'intErr is assigned an error number in the error trap
If intErr = 429 Then
Set objWord = CreateObject("Word.Application")
End If
With objWord
.Activate
Set objDoc = .Documents.Add(Template:=strTemplate)
.Visible = True
End With
With objDoc
.SaveAs strPath & strDocName
.Activate
End With
objWord.Visible = Tru
point.
Both Word and Access are Office 2003 applications.
I’m launching Word from an Access form and the application launches just
fine, using either GetObject if there’s an active session or CreateObject it
there isn’t.
If I open a document I do not have any problems, however, when I attempt to
use a template I get an error 5151 “Word was unable to read this document.
It may be corrupt.â€
If I launch Word manually the template opens just fine, but the code cannot
seem to do this. I’ve gotten a very functional error routine going, so not
all is lost, but my original goal ass not been met.
All variables in the code sample below have been explicitly declared and
when I step through the code using watch the string variables have all the
correct values
----------------------------------------------------------------------------------
strPath = DocPath() 'UDF
strTemplate = conAppPath & conDocDot
strDocName = frm.txtPlogID.Value & ".doc"
Set objWord = GetObject(, "Word.Application")
'intErr is assigned an error number in the error trap
If intErr = 429 Then
Set objWord = CreateObject("Word.Application")
End If
With objWord
.Activate
Set objDoc = .Documents.Add(Template:=strTemplate)
.Visible = True
End With
With objDoc
.SaveAs strPath & strDocName
.Activate
End With
objWord.Visible = Tru