Path/File access error - why wont it fall into the error trap?

R

redryderridesagain

Using MS Word 2003 and MS XP Professional

The following code does not seem to trap the "Path/File access" (error
75) - why would this be? What can I do to trap file open errors or
alternatively catch badly formed file names?

On Error GoTo badfile:
If FileThere(sourcefile) Then
Open sourcefile For Binary Access Read As #8
Else
GoTo badfile:
End If

Function FileThere(FileName As String) As Boolean
FileThere = (Dir(FileName) > "")
End Function

The form of the file that it is trying to open is;

X:\B\Big BearAssn\Billings\1234567-Bear Fund $1500 Jun 06 (2).doc

Thanks for your help - this is driving me squirly
 
J

Jezebel

You haven't posted enough code to diagnose. Are you saying that the code
does not throw an error even if the filename is no good?
Or is there a mistake in your error-handler, perhaps?
 
P

Perry

Eventhough file is present on the filesystem, if it is opened, you can't
open it in binary access read mode.
Therefor ,yr function FileThere() should be rewritten to read something
like:

Function FileThere(FileName As String) As Boolean
FileThere = (Dir(FileName) > "") And Not IsFileOpen(FileName)
End Function

'supporting function:
Function IsFileOpen(TargetFile as string) As Boolean
On Error GoTo ErrAccess
Dim i As Integer
i = FreeFile
Open TargetFile For Binary Access Read Lock Read As #i
Close #i
ExitHere:
Exit Function
ErrAccess:
IsFileOpen = True
Resume ExitHere
End Function

--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE
 
R

redryderridesagain

Perry,

Thanks for your suggestion - putting the file open statement in a
subroutine works. I am not sure why the on error statement in the main
routine did not catch this but hey, I've learned something.

TkxAgn
Red
 

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