The Strange Case of the (repeatedly) Disappearing Document

E

EdwardSF

I work in a transcription office, where we have several standalone computers
hooked up to a server. On the server we keep a log of work done, and I've
written a macro to send entries to a table in that log document.

There have been three occasions where the log document has simply
disappeared. Poof. Not corrupted, not deleted, just not on the server's
hard drive anymore.

It must have something to do with the macro, since no other files (that
anyone is aware of) are disappearing; but I can't find any cause-and-effect
for this. The macro gets run a hundred times a day, then every blue moon or
two it crashes because it can't find the log document anymore.

*Any* ideas what could possibly cause this? I'm open to any suggestions at
all. I have no idea what else to do. Thanks.
 
T

Travis

I actually got on here to research another problem but this was too good an
opportunity to pass up.

A number of my clients, all who use XP Pro SP2 & Office 2003 Standard (and
all patched-up to the latest releases) simply lose otherwise viable documents
off of their hard drives, for no apparent reason.

Mind you, in this case neither network drives nor fancy macros are involved;
they're all on stand-along computers with single, fast, high-capacity hard
drives.

Now I have to say in the past I was reluctant to believe them (thinking
maybe they had just accidentally deleted the file) but the other day I
witnessed it first-hand.

A document was properly saved (I actually saw the file on the hard drive),
the computer was rebooted, and when Word opened and the document was
attempted to be retrieved, it had vanished into thin air!

I of course did a complete hard drive global search for it but it had
disappeared without a trace!

What the Devil could be causing this, all on machines with over 1GB of RAM
and many GBs of free hard drive space?

(Please don't tell me it's a "swap file" problem, as the paging file is free
to expand virtually as far as it wants to on these computers).
 
B

Beth Melton

First we'd have to see the macro in order to understand what it's
doing.

Second, I suspect the file is there but as a temp file. If you are
repeatedly opening/saving/closing the file then it's possible the
macro attempts to run again during the save process. When a document
is saved a temp file is created, the original document is deleted, and
the temp file is renamed to take the place of the original file. So if
macro attempts to run at precisely the right point, in between the
deletion of the original and rename of the temp file, then there will
not be a document to open, and it crashes. Since the save process can
not be completed then the temp file is never renamed.

Check the folder where the original document is stored and see if
there are any temp files. More than likely they will be named
something like: ~wrd*.tmp. If you can open them in Word and if it is
indeed the missing document then I'd say what I described above is the
problem. To correct it I'd suggest that you head over to one of the
VBA newsgroups and see if someone there can help you modify the macro
so it will first check to see if the file exists and if it doesn't add
a wait/delay routine and then check for its existence again.

Please post all follow-up questions to the newsgroup. Requests for
assistance by email can not be acknowledged.

~~~~~~~~~~~~~~~
Beth Melton
Microsoft Office MVP

TechTrax eZine: http://mousetrax.com/techtrax/
MVP FAQ site: http://mvps.org/
 
E

EdwardSF

The problem is becoming more frequent; three times now in two weeks. On none
of the occasions was anybody else accessing the file in question; on one
occasion no one else was even using Word.

The pertinent code is below. There is an error-handling routine for when
there is a problem opening the log file. (Our boss would open the log and
leave it up on her computer, forcing everybody else to open a read-only copy.
This was later changed to try to capture the missing-log event.) When the
log disappears, though, the "don't panic" message I wrote never comes up;
instead, Word displays its own error message that it can't find the file, and
to either reconnect to the network or insert a floppy disk [RETRY/CANCEL].
Sure enough, there is a TMP file with the log in it (but not the current
entry), but the file itself has disappeared.

(Interestingly, the Word error message is caught in an infinite loop;
neither RETRY nor CANCEL closes the box. You have to CTRL-ALT-DEL and
restart Word. At which time you can recover the document you were working
on, but Word can't recover the UCSFLOG file, even though there's a TMP file
on the drive.)

So I think you're right, Beth; it *seems* that the macro is opening the log
file without a problem, makes a TMP file, removes the original and then
freaks out when it can't find it. What baffles me is why this is happening
even when there's only one person in the office running the macro, or even
using Word at all.

CODE:

'
' Some data-parsing stuff here

' Then it saves the current document for sending to the client. (They want
the file
‘ names a certain way.)
ChangeFileOpenDirectory "F:\CL\UCSFSEND\"
varFileName = "7" + varDocType + varFacNum + Right$(varJobID, 4) + "." +
varTransID
ActiveDocument.SaveAs FileName:=varFileName + ".doc"

' Next an entry is made into a table in a document called UCSFLOG.doc.
This is the Amazing Disappearing File.
‘ Sometimes the boss opens the file to get statistics, and leaves the file
open. Then if
‘ someone runs the macro, they get an error message that the file is
already open. This
‘ next block of code originally meant to deal with that, so the user could
go tell the boss
‘ to close the file then try again, without the macro bombing out. Later,
when the
‘ UCSFLOG file started disappearing entirely, the MsgBox message was more
strongly
‘ worded, but the loop was left in place.

ChangeFileOpenDirectory "F:\CL\UCSF"
TryOpen:
On Error Resume Next
Documents.Open FileName:="UCSFLOG.doc"
varError = Err.Number
If varError <> 0 Then
MsgBox ("UCSFLOG cannot be found. Something has gone seriously
wrong. Do not panic.")
GoTo TryOpen
End If

‘ Once the UCSFLOG file has been closed elsewhere (and assuming that it’s
still on the server at this point), a line is added to the table.

‘ Now, we save the UCSFLOG file, as well as (recently added) a backup copy
on an
‘ entirely separate drive.

ActiveDocument.SaveAs
ChangeFileOpenDirectory "Z:\"
ActiveDocument.SaveAs ("UCSFLOGbackup.doc")
ChangeFileOpenDirectory "F:\CL\UCSF"
ActiveDocument.Close
' Close the report as well
ActiveDocument.Close Savechanges:=wdSaveChanges

End Sub
 
B

Beth Melton

If you have found a temp file with the log but the original is missing
then the error is occuring when Word saves the file. I'm not sure if
you've done this already but as I noted before, see if someone in the
VBA newsgroups can help you modify the macro so it will first check to
see if the file exists and if it doesn't add a wait/delay routine and
then check for its existence again. Using a GoTo statement will not
resolve it - there need to be an actual delay. I've always used a
message box asking the user if they want to wait as well so there is a
way out in the event there is more to it than waiting on a file to be
written.

Also, if what you provided is the full procedure, I don't see anything
written to the log file and I don't see the Log file getting saved. I
only see opening the Log and saving it as the backup copy.

Btw, I'm not sure where you got the code for your error handler but
you need something like this instead:

On Error GoTo errOpenFile
'Code

resOpenFile:
'Code to open file
Exit Sub

errOpenFile:
Select Case Err.Number
Case <error number>
iResponse=Msgbox("Do you want to wait?", vbYesNo)
If iResponse=vbYes then
Resume resOpenFile (should call the delay routine instead)
End if
Case Else
MsgBox Err.Description
End Select
'Stop all macro execution
End
End Sub

Please post all follow-up questions to the newsgroup. Requests for
assistance by email can not be acknowledged.

~~~~~~~~~~~~~~~
Beth Melton
Microsoft Office MVP

TechTrax eZine: http://mousetrax.com/techtrax/
MVP FAQ site: http://mvps.org/

EdwardSF said:
The problem is becoming more frequent; three times now in two weeks.
On none
of the occasions was anybody else accessing the file in question; on
one
occasion no one else was even using Word.

The pertinent code is below. There is an error-handling routine for
when
there is a problem opening the log file. (Our boss would open the
log and
leave it up on her computer, forcing everybody else to open a
read-only copy.
This was later changed to try to capture the missing-log event.)
When the
log disappears, though, the "don't panic" message I wrote never
comes up;
instead, Word displays its own error message that it can't find the
file, and
to either reconnect to the network or insert a floppy disk
[RETRY/CANCEL].
Sure enough, there is a TMP file with the log in it (but not the
current
entry), but the file itself has disappeared.

(Interestingly, the Word error message is caught in an infinite
loop;
neither RETRY nor CANCEL closes the box. You have to CTRL-ALT-DEL
and
restart Word. At which time you can recover the document you were
working
on, but Word can't recover the UCSFLOG file, even though there's a
TMP file
on the drive.)

So I think you're right, Beth; it *seems* that the macro is opening
the log
file without a problem, makes a TMP file, removes the original and
then
freaks out when it can't find it. What baffles me is why this is
happening
even when there's only one person in the office running the macro,
or even
using Word at all.

CODE:

'
' Some data-parsing stuff here

' Then it saves the current document for sending to the client.
(They want
the file
' names a certain way.)
ChangeFileOpenDirectory "F:\CL\UCSFSEND\"
varFileName = "7" + varDocType + varFacNum + Right$(varJobID, 4)
+ "." +
varTransID
ActiveDocument.SaveAs FileName:=varFileName + ".doc"

' Next an entry is made into a table in a document called
UCSFLOG.doc.
This is the Amazing Disappearing File.
' Sometimes the boss opens the file to get statistics, and leaves
the file
open. Then if
' someone runs the macro, they get an error message that the file
is
already open. This
' next block of code originally meant to deal with that, so the
user could
go tell the boss
' to close the file then try again, without the macro bombing out.
Later,
when the
' UCSFLOG file started disappearing entirely, the MsgBox message
was more
strongly
' worded, but the loop was left in place.

ChangeFileOpenDirectory "F:\CL\UCSF"
TryOpen:
On Error Resume Next
Documents.Open FileName:="UCSFLOG.doc"
varError = Err.Number
If varError <> 0 Then
MsgBox ("UCSFLOG cannot be found. Something has gone
seriously
wrong. Do not panic.")
GoTo TryOpen
End If

' Once the UCSFLOG file has been closed elsewhere (and assuming
that it's
still on the server at this point), a line is added to the table.

' Now, we save the UCSFLOG file, as well as (recently added) a
backup copy
on an
' entirely separate drive.

ActiveDocument.SaveAs
ChangeFileOpenDirectory "Z:\"
ActiveDocument.SaveAs ("UCSFLOGbackup.doc")
ChangeFileOpenDirectory "F:\CL\UCSF"
ActiveDocument.Close
' Close the report as well
ActiveDocument.Close Savechanges:=wdSaveChanges

End Sub


Beth Melton said:
First we'd have to see the macro in order to understand what it's
doing.

Second, I suspect the file is there but as a temp file. If you are
repeatedly opening/saving/closing the file then it's possible the
macro attempts to run again during the save process. When a
document
is saved a temp file is created, the original document is deleted,
and
the temp file is renamed to take the place of the original file. So
if
macro attempts to run at precisely the right point, in between the
deletion of the original and rename of the temp file, then there
will
not be a document to open, and it crashes. Since the save process
can
not be completed then the temp file is never renamed.

Check the folder where the original document is stored and see if
there are any temp files. More than likely they will be named
something like: ~wrd*.tmp. If you can open them in Word and if it
is
indeed the missing document then I'd say what I described above is
the
problem. To correct it I'd suggest that you head over to one of the
VBA newsgroups and see if someone there can help you modify the
macro
so it will first check to see if the file exists and if it doesn't
add
a wait/delay routine and then check for its existence again.

Please post all follow-up questions to the newsgroup. Requests for
assistance by email can not be acknowledged.

~~~~~~~~~~~~~~~
Beth Melton
Microsoft Office MVP

TechTrax eZine: http://mousetrax.com/techtrax/
MVP FAQ site: http://mvps.org/
 

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