PC Review


Reply
Thread Tools Rate Thread

Access automation error calling a Word template

 
 
Kevin B
Guest
Posts: n/a
 
      18th Mar 2009
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
----------------------------------------------------------------------------------

Thanks ahead of time, I've been saved more than once by contributors to this
forum.
--
Kevin Backmann
 
Reply With Quote
 
 
 
 
ryguy7272
Guest
Posts: n/a
 
      19th Mar 2009
There are many ways to export data from Access to Word. Here is one:
Private Sub cmdExportToWord_Click()

Dim objWordApp As Word.Application
Dim objWord As Word.Document
Dim oSel As Word.Selection

DoCmd.OutputTo acOutputReport, "Samples", acFormatRTF, "E:\SamplesReport2.rtf"

Set objWordApp = CreateObject("Word.Application")
Set objWord = objWordApp.Documents.Open("E:\SamplesReport2.rtf")

' Make Word visible.
objWord.Application.Visible = True

Set objWord = Nothing
Set objWordApp = Nothing


End Sub

Also, look here:
http://www.members.shaw.ca/AlbertKal.../msaccess.html
http://www.members.shaw.ca/AlbertKal...rge/page2.html

Ryan---

--
RyGuy--
If the post was helpful, please click the ''Yes'' button to indicate such!


"Kevin B" wrote:

> 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 = True
> ----------------------------------------------------------------------------------
>
> Thanks ahead of time, I've been saved more than once by contributors to this
> forum.
> --
> Kevin Backmann

 
Reply With Quote
 
Kevin B
Guest
Posts: n/a
 
      19th Mar 2009
Thanks for the reply, however, I'm not exporting report data to Word. What
I"m doing is opening a new Word document where the user can enter whatever
they want.

As I said in my earlier post, the code works fine if I present the user with
an existing document, or even a new one, but fails if I create a new document
and specify a template to apply to the new document.
--
Kevin Backmann


"ryguy7272" wrote:

> There are many ways to export data from Access to Word. Here is one:
> Private Sub cmdExportToWord_Click()
>
> Dim objWordApp As Word.Application
> Dim objWord As Word.Document
> Dim oSel As Word.Selection
>
> DoCmd.OutputTo acOutputReport, "Samples", acFormatRTF, "E:\SamplesReport2.rtf"
>
> Set objWordApp = CreateObject("Word.Application")
> Set objWord = objWordApp.Documents.Open("E:\SamplesReport2.rtf")
>
> ' Make Word visible.
> objWord.Application.Visible = True
>
> Set objWord = Nothing
> Set objWordApp = Nothing
>
>
> End Sub
>
> Also, look here:
> http://www.members.shaw.ca/AlbertKal.../msaccess.html
> http://www.members.shaw.ca/AlbertKal...rge/page2.html
>
> Ryan---
>
> --
> RyGuy--
> If the post was helpful, please click the ''Yes'' button to indicate such!
>
>
> "Kevin B" wrote:
>
> > 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 = True
> > ----------------------------------------------------------------------------------
> >
> > Thanks ahead of time, I've been saved more than once by contributors to this
> > forum.
> > --
> > Kevin Backmann

 
Reply With Quote
 
ryguy7272
Guest
Posts: n/a
 
      19th Mar 2009
That sounds pretty weird. Maybe something in the Word Normal template got
corrupted. You can easily delete the Normal template and rebuild it.
http://word.mvps.org/faqs/apperrors/CorruptDoc.htm

http://www.officearticles.com/word/a...osoft_word.htm

So, see if that's the issue. If so, please resolve, then look here:
http://www.databasedev.co.uk/open_word_doc.html

Or this:
http://www.techonthenet.com/access/modules/word_doc.php

It can be frustrating to deal with Word, but rewarding too. Try the
suggestions above. I think you'll figure it out pretty soon.

Good luck,
Ryan---


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Word Automation; template showing up AJ Microsoft Access 0 26th Feb 2008 05:38 PM
calling calendar, get Automation Error =?Utf-8?B?QXJub2xkIEtsYXBoZWNr?= Microsoft Excel Programming 1 22nd Nov 2006 02:47 AM
Calling a C# assembly from Excel or Word (VBA) => Automation Error =?Utf-8?B?R3VudGhlcg==?= Microsoft C# .NET 0 3rd Apr 2006 12:01 PM
Re: Cannot add reference to Word template project via Automation Howard Kaikow Microsoft VB .NET 0 22nd Jul 2004 04:56 PM
Re: Access/Word automation question. Word doc stored in table, want to use Find. SJRockower Microsoft Access Form Coding 0 31st Aug 2003 07:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:08 PM.