Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
redryderridesagain@hotmail.com - 12 Feb 2007 09:51 GMT
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
Jezebel - 12 Feb 2007 11:44 GMT
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?

> Using MS Word 2003 and MS XP Professional
>
[quoted text clipped - 18 lines]
>
> Thanks for your help - this is driving me squirly
Perry - 12 Feb 2007 12:58 GMT
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

> Using MS Word 2003 and MS XP Professional
>
[quoted text clipped - 18 lines]
>
> Thanks for your help - this is driving me squirly
redryderridesagain@hotmail.com - 17 Feb 2007 22:24 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.