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

Re: Path/File access error - why wont it fall into the error trap? by Jezebel

Jezebel
Mon Feb 12 05:44:10 CST 2007

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?





<redryderridesagain@hotmail.com> wrote in message
news:1171273915.799946.44590@m58g2000cwm.googlegroups.com...
> 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
>



Re: Path/File access error - why wont it fall into the error trap? by Perry

Perry
Mon Feb 12 06:58:20 CST 2007

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



<redryderridesagain@hotmail.com> schreef in bericht
news:1171273915.799946.44590@m58g2000cwm.googlegroups.com...
> 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
>


Re: Path/File access error - why wont it fall into the error trap? by redryderridesagain

redryderridesagain
Sat Feb 17 16:24:44 CST 2007

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