corrupt doc file ends procedure

C

Co

Hi All,

we have a procedure which automatically opens a batch of doc files
from within an access database
and searches these docs for certain important words. Sometimes there
is a document that has gone corrupt.
When the procedure stumbles across this document the code stops.
Is there any way to prevent this?

Regards
Marco
 
M

macropod

Hi Marco,

You need to add some error-trapping to your code. At its most basic, that could be an
On Error Resume Next
statement strategically placed in your code.
 
C

Co

Hi Marco,

You need to add some error-trapping to your code. At its most basic, that could be an
On Error Resume Next
statement strategically placed in your code.

--
Cheers
macropod
[MVP - Microsoft Word]



Co said:
we have a procedure which automatically opens a batch of doc files
from within an access database
and searches these docs for certain important words. Sometimes there
is a document that has gone corrupt.
When the procedure stumbles across this document the code stops.
Is there any way to prevent this?
Regards
Marco- Tekst uit oorspronkelijk bericht niet weergeven -

- Tekst uit oorspronkelijk bericht weergeven -

I think when Word is opening a file the error won't get trapped before
the message gets to the screen
telling you that the file might be corrupted. That way I can't skip
this file before the error is detected.

Marco
 
A

alborg

Hi Marco:

I'd think that "On Error Resume Next" would work, but I guess it's all in
the timing.

Since I never have come up with this issue when opening documents, some of
which have been corrupt, I looked at my boilerplate code that I use all the
time, and lo and behold there are 2 statements which catch errors. One tries
to open the document from a getobject to a createobject, and if this doesn't
work, the other traps the error in an "application.quit" statement. Here is
the sample code:

Dim accessword As AccessObject
Dim oword As Word.Application
Dim wordwasnotrunning As Boolean
Set oword = GetObject("C:\Foldername\MyNewWordDoc.doc", "Word.Application")
oword.Application.Visible = True
If Err.Number <> 0 Then
Set oword = CreateObject("Word.Application")
End If
If Wordwasnotrunning = True Then
oword.Application.Quit
End If
With oword
..WindowState = wdWindowStateMaximize
End With
Set oword = Nothing

Try that and see if this resolves the issue...

Cheers,
Al

Co said:
Hi Marco,

You need to add some error-trapping to your code. At its most basic, that could be an
On Error Resume Next
statement strategically placed in your code.

--
Cheers
macropod
[MVP - Microsoft Word]



Co said:
we have a procedure which automatically opens a batch of doc files
from within an access database
and searches these docs for certain important words. Sometimes there
is a document that has gone corrupt.
When the procedure stumbles across this document the code stops.
Is there any way to prevent this?
Regards
Marco- Tekst uit oorspronkelijk bericht niet weergeven -

- Tekst uit oorspronkelijk bericht weergeven -

I think when Word is opening a file the error won't get trapped before
the message gets to the screen
telling you that the file might be corrupted. That way I can't skip
this file before the error is detected.

Marco
 
A

alborg

Oh- I forgot...

If you wish to delete a document that is corrupted, you can add the "kill"
statement-
Kill "C:\Foldername\MyNewWordDoc.doc"

Al

alborg said:
Hi Marco:

I'd think that "On Error Resume Next" would work, but I guess it's all in
the timing.

Since I never have come up with this issue when opening documents, some of
which have been corrupt, I looked at my boilerplate code that I use all the
time, and lo and behold there are 2 statements which catch errors. One tries
to open the document from a getobject to a createobject, and if this doesn't
work, the other traps the error in an "application.quit" statement. Here is
the sample code:

Dim accessword As AccessObject
Dim oword As Word.Application
Dim wordwasnotrunning As Boolean
Set oword = GetObject("C:\Foldername\MyNewWordDoc.doc", "Word.Application")
oword.Application.Visible = True
If Err.Number <> 0 Then
Set oword = CreateObject("Word.Application")
End If
If Wordwasnotrunning = True Then
oword.Application.Quit
End If
With oword
.WindowState = wdWindowStateMaximize
End With
Set oword = Nothing

Try that and see if this resolves the issue...

Cheers,
Al

Co said:
Hi Marco,

You need to add some error-trapping to your code. At its most basic, that could be an
On Error Resume Next
statement strategically placed in your code.

--
Cheers
macropod
[MVP - Microsoft Word]



Hi All,

we have a procedure which automatically opens a batch of doc files
from within an access database
and searches these docs for certain important words. Sometimes there
is a document that has gone corrupt.
When the procedure stumbles across this document the code stops.
Is there any way to prevent this?

Regards
Marco- Tekst uit oorspronkelijk bericht niet weergeven -

- Tekst uit oorspronkelijk bericht weergeven -

I think when Word is opening a file the error won't get trapped before
the message gets to the screen
telling you that the file might be corrupted. That way I can't skip
this file before the error is detected.

Marco
 
M

macropod

Hi Marco,

If opening the document fails, then having a:
On Error Resume Next
line immediately before your 'open' code will prevent the code from failing at that point.

If trying to read something from the file causes the failure, then having a:
On Error Resume Next
line immediately before your 'read' code will prevent the code from failing at that point.

All you need to work out, then, is what to do with anything that relied on the document being opened and read correctly. Usually,
you'd do this with a statement like:
On Error Goto DocErr
or
On Error Goto ReadErr
where 'DocErr' and 'ReadErr' are the entry points to your error-handling routines.

--
Cheers
macropod
[MVP - Microsoft Word]


Co said:
Hi Marco,

You need to add some error-trapping to your code. At its most basic, that could be an
On Error Resume Next
statement strategically placed in your code.

--
Cheers
macropod
[MVP - Microsoft Word]



Co said:
we have a procedure which automatically opens a batch of doc files
from within an access database
and searches these docs for certain important words. Sometimes there
is a document that has gone corrupt.
When the procedure stumbles across this document the code stops.
Is there any way to prevent this?
Regards
Marco- Tekst uit oorspronkelijk bericht niet weergeven -

- Tekst uit oorspronkelijk bericht weergeven -

I think when Word is opening a file the error won't get trapped before
the message gets to the screen
telling you that the file might be corrupted. That way I can't skip
this file before the error is detected.

Marco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top