[AccessD] Problem with Opening a Word document from within Access

Max Wanadoo max.wanadoo at gmail.com
Mon Jul 20 09:10:14 CDT 2009


Could it be an office update which has changed things?

Max


-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Mike Mattys
Sent: 20 July 2009 14:47
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Problem with Opening a Word document from within
Access

Hi Arthur,

Maybe you have an instance already running in Task Manager.
Sometimes it doesn't warn you.

-
Michael R Mattys
MapPoint and Database Dev
www.mattysconsulting.com
-

----- Original Message ----- 
From: "Arthur Fuller" <fuller.artful at gmail.com>
To: "Access Developers discussion and problem solving" 
<accessd at databaseadvisors.com>
Sent: Monday, July 20, 2009 9:30 AM
Subject: [AccessD] Problem with Opening a Word document from within Access


> This one is very bizarre, folks. The app in question has been in use for
> several years and the following code snippet now fails on my home machine.
> Basically it opens a Word template file and then fills its bookmarks with
> values from Access.
>
> Now, for some reason, I am able to run this code successfully. The 
> template
> file exists and I can open it manually from Word without problems. But the
> following code snippet fails on the last line, when it attempts to get the
> bookmark count. The reason is that the document is not open. Word is open
> and visible, but the document is not loaded. I have no idea why this is
> happening. Do you have any suggestions?
>
> <vba code>
>
>    Set objWord = GetObject(, "Word.Application")
>    If Err.Number <> 0 Then
>      Set objWord = CreateObject("Word.Application")
>    End If
>    ' Launch Word and load the invoice template
>    On Error GoTo Create_PSR_Doc_Error
>
>    'Make sure we have a Word Instance
>    If objWord Is Nothing Then
>      Err.Raise 65355, "Create_PSR_Doc", "Word is not available"
>    End If
>    'Set objWord = New Word.Application
>    Dim doc As Word.Document
>    Dim strTemplateFile As String
>
>    strTemplateFile = "C:\DSA\Document
> Templates\PSR_Report_Template_20060223.dot"   'TEMPLATEPATH
>    Set doc = objWord.Documents.Add(strTemplateFile)
>    objWord.Visible = True
>    ' At this point, Word is visible, but the document is not loaded
>    Debug.Print "Bookmark count:", objWord.ActiveDocument.Bookmarks.Count
>    ' Code crashes on the line above
> </vba code>
>
> It gets stranger. I just inserted a break point on the third last line 
> (the
> "Set doc" line) and began to single-step. After running this line, the doc
> variable is nothing. I am deeply puzzled by this. Any suggestions you 
> might
> have would be greatly appreciated. I'm going to try this code on my 
> notebook
> computer and see if it has the same strange behaviour.
>
> Thanks,
> Arthur
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com 

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list