|
|
|
date: Wed, 10 Aug 2005 14:45:22 +1000,
group: microsoft.public.access.interopoledde
back
Export To Word Problem
I've got a procedure that is exporting data to Word okay the first time it
is run, but then in the second and subsequent calls it gives me the
following error: "462 - The remote server machine does not exist or is
unavailable".
I close and save the Word document within the procedure, and release the
variable as required. The relevant lines of code are as follows:
Dim objWordDoc As Word.Document
Set objWordDoc = New Word.Document
Set objWordDoc = Word.Documents.Open(inFileName, , , , , , , , , , , False)
<fails here>
<code in here to export to Bookmarks within the document>
objWordDoc.Close (wdSaveChanges)
Set objWordDoc = Nothing
When I close Access (2003) and restart it works again for the first call and
then fails again on subsequent calls.
Any ideas where the problem might be?
Thanks,
Vilem Sova
date: Wed, 10 Aug 2005 14:45:22 +1000
author: Vilem Sova
Re: Export To Word Problem
Hi Vilem,
Try something like this:
Dim objWordDoc As Word.Document
Set objWordDoc = GetObject(inFileName)
...
objWordDoc.Close True
Set objWordDoc = Nothing
On Wed, 10 Aug 2005 14:45:22 +1000, "Vilem Sova"
wrote:
>I've got a procedure that is exporting data to Word okay the first time it
>is run, but then in the second and subsequent calls it gives me the
>following error: "462 - The remote server machine does not exist or is
>unavailable".
>
>I close and save the Word document within the procedure, and release the
>variable as required. The relevant lines of code are as follows:
>
>Dim objWordDoc As Word.Document
>
>Set objWordDoc = New Word.Document
>Set objWordDoc = Word.Documents.Open(inFileName, , , , , , , , , , , False)
><fails here>
>
> <code in here to export to Bookmarks within the document>
>
>objWordDoc.Close (wdSaveChanges)
>Set objWordDoc = Nothing
>
>When I close Access (2003) and restart it works again for the first call and
>then fails again on subsequent calls.
>
>Any ideas where the problem might be?
>
>Thanks,
>Vilem Sova
>
>
>
>
--
John Nurick [Microsoft Access MVP]
Please respond in the newgroup and not by email.
date: Wed, 10 Aug 2005 07:02:44 +0100
author: John Nurick
Re: Export To Word Problem
I get the following error: Automation Error - Invalid Syntax.
It does, however, compile ok.
Thanks,
Vilem
"John Nurick" wrote in message
news:785jf1p1sn9q35n29756hfeevsp8kivnjb@4ax.com...
> Hi Vilem,
>
> Try something like this:
>
> Dim objWordDoc As Word.Document
>
> Set objWordDoc = GetObject(inFileName)
> ...
> objWordDoc.Close True
> Set objWordDoc = Nothing
>
> On Wed, 10 Aug 2005 14:45:22 +1000, "Vilem Sova"
> wrote:
>
> >I've got a procedure that is exporting data to Word okay the first time
it
> >is run, but then in the second and subsequent calls it gives me the
> >following error: "462 - The remote server machine does not exist or is
> >unavailable".
> >
> >I close and save the Word document within the procedure, and release the
> >variable as required. The relevant lines of code are as follows:
> >
> >Dim objWordDoc As Word.Document
> >
> >Set objWordDoc = New Word.Document
> >Set objWordDoc = Word.Documents.Open(inFileName, , , , , , , , , , ,
False)
> ><fails here>
> >
> > <code in here to export to Bookmarks within the document>
> >
> >objWordDoc.Close (wdSaveChanges)
> >Set objWordDoc = Nothing
> >
> >When I close Access (2003) and restart it works again for the first call
and
> >then fails again on subsequent calls.
> >
> >Any ideas where the problem might be?
> >
> >Thanks,
> >Vilem Sova
> >
> >
> >
> >
>
> --
> John Nurick [Microsoft Access MVP]
>
> Please respond in the newgroup and not by email.
date: Thu, 11 Aug 2005 08:42:22 +1000
author: Vilem Sova
Re: Export To Word Problem
Which line of code raises the error?
On Thu, 11 Aug 2005 08:42:22 +1000, "Vilem Sova"
wrote:
>I get the following error: Automation Error - Invalid Syntax.
>
>It does, however, compile ok.
>
>Thanks,
>Vilem
>
>"John Nurick" wrote in message
>news:785jf1p1sn9q35n29756hfeevsp8kivnjb@4ax.com...
>> Hi Vilem,
>>
>> Try something like this:
>>
>> Dim objWordDoc As Word.Document
>>
>> Set objWordDoc = GetObject(inFileName)
>> ...
>> objWordDoc.Close True
>> Set objWordDoc = Nothing
>>
>> On Wed, 10 Aug 2005 14:45:22 +1000, "Vilem Sova"
>> wrote:
>>
>> >I've got a procedure that is exporting data to Word okay the first time
>it
>> >is run, but then in the second and subsequent calls it gives me the
>> >following error: "462 - The remote server machine does not exist or is
>> >unavailable".
>> >
>> >I close and save the Word document within the procedure, and release the
>> >variable as required. The relevant lines of code are as follows:
>> >
>> >Dim objWordDoc As Word.Document
>> >
>> >Set objWordDoc = New Word.Document
>> >Set objWordDoc = Word.Documents.Open(inFileName, , , , , , , , , , ,
>False)
>> ><fails here>
>> >
>> > <code in here to export to Bookmarks within the document>
>> >
>> >objWordDoc.Close (wdSaveChanges)
>> >Set objWordDoc = Nothing
>> >
>> >When I close Access (2003) and restart it works again for the first call
>and
>> >then fails again on subsequent calls.
>> >
>> >Any ideas where the problem might be?
>> >
>> >Thanks,
>> >Vilem Sova
>> >
>> >
>> >
>> >
>>
>> --
>> John Nurick [Microsoft Access MVP]
>>
>> Please respond in the newgroup and not by email.
>
--
John Nurick [Microsoft Access MVP]
Please respond in the newgroup and not by email.
date: Thu, 11 Aug 2005 07:11:01 +0100
author: John Nurick
Re: Export To Word Problem
Hi John,
The line that was causing the error was:
Set objWordDoc = GetObject(inFileName)
The line below required the input file name to be surrounded with
double-quotes to work:
Set objWordDoc = Word.Documents.Open(inFileName, , , , , , , , , , , False)
I then tried removing the double-quotes in the file name for the line you
suggested, and it now seems to be working fine.
So thanks very much for your help. Much appreciated.
(But I'm still very curious as to why my original line works the first time
and then fails on subsequent calls)
Regards,
Vilem
"John Nurick" wrote in message
news:0vqlf1paptfvh7ie21lnp0h1oet5fff24a@4ax.com...
> Which line of code raises the error?
>
>
> On Thu, 11 Aug 2005 08:42:22 +1000, "Vilem Sova"
> wrote:
>
> >I get the following error: Automation Error - Invalid Syntax.
> >
> >It does, however, compile ok.
> >
> >Thanks,
> >Vilem
> >
> >"John Nurick" wrote in message
> >news:785jf1p1sn9q35n29756hfeevsp8kivnjb@4ax.com...
> >> Hi Vilem,
> >>
> >> Try something like this:
> >>
> >> Dim objWordDoc As Word.Document
> >>
> >> Set objWordDoc = GetObject(inFileName)
> >> ...
> >> objWordDoc.Close True
> >> Set objWordDoc = Nothing
> >>
> >> On Wed, 10 Aug 2005 14:45:22 +1000, "Vilem Sova"
> >> wrote:
> >>
> >> >I've got a procedure that is exporting data to Word okay the first
time
> >it
> >> >is run, but then in the second and subsequent calls it gives me the
> >> >following error: "462 - The remote server machine does not exist or is
> >> >unavailable".
> >> >
> >> >I close and save the Word document within the procedure, and release
the
> >> >variable as required. The relevant lines of code are as follows:
> >> >
> >> >Dim objWordDoc As Word.Document
> >> >
> >> >Set objWordDoc = New Word.Document
> >> >Set objWordDoc = Word.Documents.Open(inFileName, , , , , , , , , , ,
> >False)
> >> ><fails here>
> >> >
> >> > <code in here to export to Bookmarks within the document>
> >> >
> >> >objWordDoc.Close (wdSaveChanges)
> >> >Set objWordDoc = Nothing
> >> >
> >> >When I close Access (2003) and restart it works again for the first
call
> >and
> >> >then fails again on subsequent calls.
> >> >
> >> >Any ideas where the problem might be?
> >> >
> >> >Thanks,
> >> >Vilem Sova
> >> >
> >> >
> >> >
> >> >
> >>
> >> --
> >> John Nurick [Microsoft Access MVP]
> >>
> >> Please respond in the newgroup and not by email.
> >
>
> --
> John Nurick [Microsoft Access MVP]
>
> Please respond in the newgroup and not by email.
date: Fri, 12 Aug 2005 09:56:50 +1000
author: Vilem Sova
Re: Export To Word Problem
On Fri, 12 Aug 2005 09:56:50 +1000, "Vilem Sova"
wrote:
>(But I'm still very curious as to why my original line works the first time
>and then fails on subsequent calls)
I didn't answer that specifically because I didn't have time to trace
things properly. But I think that in your original code this line
>Set objWordDoc = New Word.Document
launches an instance of Word, creates a new blank document, and points
objWordDoc to the object corresponding to that document. The next line
>Set objWordDoc = Word.Documents.Open(inFileName, , , , , , , , , , , False)
opens the doc file (creating a new Word.Document object) and points
objWordDoc to that objec. As a result, you have "orphaned" the original
blank document which hangs round and prevents the instance of Word from
closing. I also suspect that there may be a problem with
Word.Documents.Open
which would normally be interpreted as calling a method of an object
variable called Word - and you haven't explicitly declared and
instantiated one. Conceivably this would be better
Set objWordDoc = objWordDoc.Parent.Documents.Open(blah blah)
- not least because it makes it more obvious that you're orphaning the
original blank document.
--
John Nurick [Microsoft Access MVP]
Please respond in the newgroup and not by email.
date: Fri, 12 Aug 2005 07:36:31 +0100
author: John Nurick
Re: Export To Word Problem
Hi there!
Sorry that I didn't get to this earlier, but here's how I'd solve this
problem...
PROBLEM CODE:
Dim objWordDoc As Word.Document
Set objWordDoc = New Word.Document
Set objWordDoc = Word.Documents.Open(inFileName, , , , , , , , , , , False)
<fails here>
<code in here to export to Bookmarks within the document>
objWordDoc.Close (wdSaveChanges)
Set objWordDoc = Nothing
TRY:
Dim objWordDocAs Object 'Word.Application
Dim WordRunning As Boolean
Dim wdWindowStateMaximize As Long
On Error Resume Next
wdWindowStateMaximize = 1
err.Clear
Set objWordDoc = GetObject(, "Word.Application")
If err.Number <> 0 Then
WordRunning = False
Else
WordRunning = True
End If
err.Clear
If WordRunning = False Then
Set objWordDoc = CreateObject("Word.Application")
If err.Number <> 0 Then
Exit Sub
End If
End If
With objWordDoc
.Documents.ADD "C:\program files\zfilemds\Templates\test11.doc" '
open your Word document
.WindowState = wdWindowStateMaximize
.ActiveDocument.ShowSpellingErrors = True
appWord.Visible = True
etc etc etc
..Close (wdSaveChanges)
End With
Set objWordDoc = Nothing
Al
(writer of the free MS Word EMR Project, downloadable at
http://www.emrupdate.com/freestuff/alborgesmd.aspx)
----- Original Message -----
From: "John Nurick"
Newsgroups: microsoft.public.access.interopoledde
Sent: Friday, August 12, 2005 2:36 AM
Subject: Re: Export To Word Problem
> On Fri, 12 Aug 2005 09:56:50 +1000, "Vilem Sova"
> wrote:
>
>>(But I'm still very curious as to why my original line works the first
>>time
>>and then fails on subsequent calls)
>
> I didn't answer that specifically because I didn't have time to trace
> things properly. But I think that in your original code this line
>
>>Set objWordDoc = New Word.Document
>
> launches an instance of Word, creates a new blank document, and points
> objWordDoc to the object corresponding to that document. The next line
>
>>Set objWordDoc = Word.Documents.Open(inFileName, , , , , , , , , , ,
>>False)
>
> opens the doc file (creating a new Word.Document object) and points
> objWordDoc to that objec. As a result, you have "orphaned" the original
> blank document which hangs round and prevents the instance of Word from
> closing. I also suspect that there may be a problem with
> Word.Documents.Open
> which would normally be interpreted as calling a method of an object
> variable called Word - and you haven't explicitly declared and
> instantiated one. Conceivably this would be better
> Set objWordDoc = objWordDoc.Parent.Documents.Open(blah blah)
> - not least because it makes it more obvious that you're orphaning the
> original blank document.
>
> --
> John Nurick [Microsoft Access MVP]
>
> Please respond in the newgroup and not by email.
date: Wed, 5 Oct 2005 07:22:52 -0400
author: Al Borges
|
|