Problem with Stream and Word Object 
Author Message
 Problem with Stream and Word Object

Hi

I have an application that uses ADODB.Stream to save a and retrieve Word
documents fromand SQL 7 table.

I have a class called WordApp which declares a Word Object so:

Dim WithEvents objWord as Word.Application

The Word app then loads a file called "C:\Temp.doc" for editing.  When the
user closes Word, the Class captures this with

Private Sub objWord_Quit
    Dim stmStream as ADODB.Stream
    Set stmStream = New Stream
    With stmStream
        .Type = adTypeBinary
        .Open
        .LoadFromFile "C:\Temp.doc"
    End With

End Sub

Now, when I run the program, after quitting Word I get an error 3002 , File
could not be opened at the line .LoadFromFile.  Word does not completely
quit until the procedure objWord_Quit has completed.  Once Word has
completely unloaded, only then could I not get an error, but how do I get
Word to completely unload ?  As fas as I can see, Word has saved this
document but it doesn't seem to "release" it until Word itself is
terminated.

Does anyone have any ideas as to how I can work around this problem ?

Many Thanks in advance

Simon



Sun, 24 Oct 2004 01:20:12 GMT  
 Problem with Stream and Word Object
Hi,

Check if you do not have instance of Word in memory. I
think that you did not release your Word object variable
or did not close Word properly. in that case it keeps file
and you cannot read from it

Val
Microsoft MVP

Quote:
>-----Original Message-----
>Hi

>I have an application that uses ADODB.Stream to save a
and retrieve Word
>documents fromand SQL 7 table.

>I have a class called WordApp which declares a Word
Object so:

>Dim WithEvents objWord as Word.Application

>The Word app then loads a file called "C:\Temp.doc" for
editing.  When the
>user closes Word, the Class captures this with

>Private Sub objWord_Quit
>    Dim stmStream as ADODB.Stream
>    Set stmStream = New Stream
>    With stmStream
>        .Type = adTypeBinary
>        .Open
>        .LoadFromFile "C:\Temp.doc"
>    End With

>End Sub

>Now, when I run the program, after quitting Word I get an
error 3002 , File
>could not be opened at the line .LoadFromFile.  Word does
not completely
>quit until the procedure objWord_Quit has completed.  
Once Word has
>completely unloaded, only then could I not get an error,
but how do I get
>Word to completely unload ?  As fas as I can see, Word
has saved this
>document but it doesn't seem to "release" it until Word
itself is
>terminated.

>Does anyone have any ideas as to how I can work around
this problem ?

>Many Thanks in advance

>Simon

>.



Sun, 24 Oct 2004 02:06:56 GMT  
 Problem with Stream and Word Object

Val,

Thanks for the reply.

No, I don't have any other instances of Word running (except the one
that is trying to terminate !)

Simon

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Sun, 24 Oct 2004 02:36:35 GMT  
 Problem with Stream and Word Object


Hi

I have an application that uses ADODB.Stream to save a and retrieve Word
documents fromand SQL 7 table.

I have a class called WordApp which declares a Word Object so:

Dim WithEvents objWord as Word.Application

The Word app then loads a file called "C:\Temp.doc" for editing.  When the
user closes Word, the Class captures this with

Private Sub objWord_Quit
    Dim stmStream as ADODB.Stream
    Set stmStream = New Stream
    With stmStream
        .Type = adTypeBinary
        .Open
        .LoadFromFile "C:\Temp.doc"
    End With

End Sub

Now, when I run the program, after quitting Word I get an error 3002 , File
could not be opened at the line .LoadFromFile.  Word does not completely
quit until the procedure objWord_Quit has completed.  Once Word has
completely unloaded, only then could I not get an error, but how do I get
Word to completely unload ?  As fas as I can see, Word has saved this
document but it doesn't seem to "release" it until Word itself is
terminated.

Does anyone have any ideas as to how I can work around this problem ?

It sounds like you haven't destroyed all the object instances that have been
created in Word. For example, in the above code you never terminate the Stream
object and set it to Nothing but simply allow it to go out of scope

You need to be very judicious about cleaning up object references in the Office
apps, otherwise they will not unload from memory.


Microsoft MVP (Visual Basic)



Sun, 24 Oct 2004 02:37:46 GMT  
 Problem with Stream and Word Object
Paul

I cannot terminate the stream. It is the stream that is throwing this
error !

Simon

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Sun, 24 Oct 2004 03:32:12 GMT  
 Problem with Stream and Word Object


Paul

I cannot terminate the stream. It is the stream that is throwing this
error !

So if you set a debug breakpoint on the Open statement you can check to verify
whether the file exists prior to executing the LoadFromFile method?


Microsoft MVP (Visual Basic)



Sun, 24 Oct 2004 21:43:32 GMT  
 Problem with Stream and Word Object
Paul

Taking on board what you have said, I changed the code to read:

Private Sub objWord_Quit()
Dim stmStream as ADODB.Stream

objWord.Quit
Set objWord=Nothing
Set stmStream = New Stream
With stmStream
   .Type = adTypeBinary
   .Open
   .LoadFromFile "C:\TempTempL.doc"  <--- Break point set
End with

Set stmStream = Nothing

End Sub

Still generates the same error, and when I insert the break point and
look on the C: drive for the doc file, I find it (and ~$mpTempL.doc), so
no luck there !!

Any other ideas ?

Once the program has gone past the End Sub line then Word will quit,
however I want to find out when the user has quit Word so that I can
then place the document into my SQL database (using Stream).  If I can
catch this somewhere else in the calling Form, then that would be great.
I have tried to use Events, but if they are generated from within the
objWord_Quit event then the program does not go past the End Sub line
and "release" Word prior to executing code associated with the Events.

Simon

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Mon, 25 Oct 2004 18:47:24 GMT  
 Problem with Stream and Word Object


Paul

Taking on board what you have said, I changed the code to read:

Private Sub objWord_Quit()
Dim stmStream as ADODB.Stream

objWord.Quit
Set objWord=Nothing
Set stmStream = New Stream
With stmStream
   .Type = adTypeBinary
   .Open
   .LoadFromFile "C:\TempTempL.doc"  <--- Break point set
End with

Set stmStream = Nothing

End Sub

Still generates the same error, and when I insert the break point and
look on the C: drive for the doc file, I find it (and ~$mpTempL.doc), so
no luck there !!

Any other ideas ?

If doesn't make sense to me that the only file present is the temporary one. Has
the document been closed before attempting to exit from Word?


Microsoft MVP (Visual Basic)



Mon, 25 Oct 2004 20:30:49 GMT  
 Problem with Stream and Word Object
Paul

No, both the temp file and TempTempL.doc are present.

Simon

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Mon, 25 Oct 2004 21:03:33 GMT  
 Problem with Stream and Word Object


Paul

No, both the temp file and TempTempL.doc are present.

...and TempTempL.doc has been closed in Word?

Just a guess but have you tried changing the name of the document to something
that doesn't have the word "temp" in it?


Microsoft MVP (Visual Basic)



Tue, 26 Oct 2004 20:19:55 GMT  
 Problem with Stream and Word Object
Paul

Have no tried this by changing the name of the document file not to
include any reference to temp.  Sadly no change !

Simon

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Fri, 29 Oct 2004 20:23:26 GMT  
 Problem with Stream and Word Object


Paul

Yup, Word has closed the document.  I'll try changing the name as you
suggest.

BTW II had an odd occurance yesterday, I wonder if it's related.  I was
compiling a DLL, which generated an error (correctly as it was a typo).
I corrected the error and tried to recompile, however I got an error
message saying that the DLL I was trying to compile to was in use
(similar problem ??), therefore, could this be a Windows problem ?

The DLL was probably loaded by another process or the VB IDE. You may need to
shut down the IDE and reopen VB to unload the DLL.

I'm not sure what else to suggest. I'm assuming that if you use the Dir command
on the file from your Quit event it returns the path? I'm not aware of any
problems with LoadFromFile.


Microsoft MVP (Visual Basic)



Sun, 31 Oct 2004 03:03:41 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. Stream object problem on Windows 98/Me

2. Security problem with ADO Streaming Object

3. DX9 - Playing a streaming sound from a memory stream (not file stream)

4. Filling an ADODB Stream object directly from a StdPicture object

5. How to get Word document as stream?

6. Capture Print Stream to Word Document

7. Streaming Wav Audio from a UDP network stream to the sound card

8. ADODB.stream instead of ADODB.Stream

9. ADODB.stream instead of ADODB.Stream??

10. ADODB.stream instead of ADODB.Stream??

11. ADO Stream Object??

12. Create stream object from pipe

 

 
Powered by phpBB® Forum Software