Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Microsoft Office Document Imaging problem

Status
Not open for further replies.

dejfatman

Programmer
Jan 24, 2002
34
0
0
US
I am having an issue releasing a file opened using the MODI library. Here is the code (docTif is the MiDocView object on my form):

Dim tmpTif As String
Dim tmpDoc As Document
Dim tmpImg as MODI.Image
...
(a TIF is created and saved to disk. the name of the file is stored in tmpTif)
...
Set tmpDoc = New Document
tmpDoc.Create tmpTif
docTif.Document = tmpDoc
Set tmpDoc = Nothing
...
(at this point, the tif is loaded to the document viewer. later in the code, I want to release the TIF and remove it)
...
Set tmpDoc = docTif.Document
Set tmpImg = tmpDoc.Images(0)
tmpDoc.Images.Remove tmpImg
Set tmpDoc = Nothing
Set tmpImg = Nothing
If Dir(tmpTif) <> "" Then Kill tmpTif

The code keeps abending on the 'Kill' statement with a permission denied. If I try to open the TIF while in this routine with Microsoft Office Document Imaging, it also tells me the file is in use. However, after the form is unloaded, the file is accessible. The problem is that I cannot clean up the temporary TIF file because I cannot 'Kill' it before the form unloads.

By the way, 'Set docTif = Nothing" gives an 'object required' error. 'docTif = Nothing" isn't supported.

Any ideas?
 
Well, you can't kill tmpTif if the docTif object still references it, as it appears to do from the code you've included.

HTH

Bob
 
I am not sure how to remove the reference. 'Set doctif.document = nothing' does not work.
 
I figured out something that worked. I changed the last part of the code to:

Set tmpDoc = New Document
tmpDoc.Create
docTiff.Document = tmpDoc
Set tmpDoc = Nothing
If Dir(tmpTif) <> "" Then Kill tmpTif

Creating an empty document and setting the miDocView.Document property to it seems to have removed the reference.

Thanks
 
>'Set doctif.document = nothing' does not work.

Well, no it wouldn't. docTif is the object that's holding open the file, not docTif.Document.

Although you don't explain what you're using docTif for, and even spell it 2 different ways,
Code:
Set docTif = nothing
should work too.

As a general observation, your solution is needlessly convoluted. I suspect that you could accomplish what you're trying to do with 1/3 of the code that you're actually using. (This is a consequence of moving on as soon as you have the code working, rather than continuing to investigate until you know WHY it's working and why it wasn't before.) If you take concepts like this and scale them up you will have a pile of "spaghetti code" in the end, and nobody will like you anymore.

:)

Bob
 
Bob,

Using 'Set docTif = Nothing' throws an 'object required' error. I mentioned that in my first post.

As for the convoluted manner of displaying/releasing the TIF in the document viewer, I have not had much success finding anything online describing an easier way to do it.

And yes, it should be docTif, not docTiff. Thanks for noticing. ;-)
 
>I mentioned that in my first post.

Sorry, missed that. All right, and now I also see that docTif is a control on your form, so I can see the line of your thinking better. I take back my assessment that your program is "needlessly" convoluted. :) It might be, it might not be...

You set the document property of the docTif control, and didn't unset it. There are actually two references to the file: doctif.document and tmpdoc. You removed the latter reference but not the former one, and I'm still sure that that's why you've had trouble.

It seems to me, and also I'm sure to you, that a getting around this by setting the doctif.document property to reference a dummy file is a kludge. It might be a necessary one, but I'd look around on the control for some means of dropping the document reference. Setting doctif.document to nothing is a good try, but there may be some internal method the control wants you to use.

HTH

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top