Test for existence of a network drive

Atomic Shrimp

Humanoid lifeform
Local time
Today, 14:49
Joined
Jun 16, 2000
Messages
1,953
I have an application that runs on a scheduled hourly basis, it's querying linked tables that reside on the file server.

Because of the type of operations it's doing (also deleting temporary objects from the server and reimporting) it cocks up terribly if it tries to run if the server is down and the network drive is therefore not available.

So, I thought, all I need to do is create a file called "ImHere.txt" on the network drive and then just do:

If Dir "G:\ImHere.txt" = "" then
'Email the IT dept
'Shut down the app
End If

but the trouble is that if the network is down, the Dir function returns the error "device unavailable", so my idea doesn't really work.

Any suggestions?

Mike
 
an answer is already there for you. use Error Handling to trap the particular error number that is thrown when the Dir() fails because of the network problems.

When the particular error occours, run code that will perform the recovery operations you want.

the following function can be used to test a file path, the return codes can be used by you to determine what to do.

_______________________________________

Function CheckFilePathValid(strFilePath As String) As Long
    Const ERR_SUCCESS = 0
    Const ERR_NOTFOUND = 1
    Const ERR_NOACCESS = 2
    Const ERR_NETDOWN = 3

    Dim strResult As String

    On Error GoTo Err_Handler

    If Dir(strFilePath) <> "" Then
        CheckFilePathValid = ERR_SUCCESS
    Else
        CheckFilePathValid = ERR_NOTFOUND
    End If

Exit_Here:
    Exit Function

Err_Handler:
    Select Case Err.Number
        Case 68 '--device unavailable; either drive not mapped or inaccessable
            CheckFilePathValid = ERR_NETDOWN
            Resume Exit_Here
        Case 76 '--path not found; either you do not have permissions
'--to folder(s) in path or path invalid/inaccessable
            CheckFilePathValid = ERR_NOACCESS
            Resume Exit_Here
        Case Else
'--raise standard error dialogue for other error messages
            Err.Raise Err.Number
            Resume Exit_Here
    End Select
End Function
_______________________________________

hope that helps

axa

[This message has been edited by axa (edited 03-20-2001).]
 
Thanks, I'll have a look.

I suspect I'm going to have to do custom error trapping, which I hate.

Mike
 
Thanks axa, I really appreciate that.

(I must have been posting my last comment at the same time as you).

I've never really gone into error trapping in any great detail, but your example is a great kick-start, thanks again.

Mike
 
glad to be of service mike.

oh by the way ignore the following line in the code listing.

Dim strResult As String

i was going to use it but then did something different, but forget to take it out...

random, useless variables make life interesting
smile.gif


axa
 
Axa's post was full with lot of '&nbsp' nonsense.

Let's see if I get this correct: Error 68 and 76 is all I need to trap when testing for network device?

I'm updating my error logging utility so it will automatically write a text file should it be unable to connect to the back-end across the network (where the error log is usually located). The thing was that I didn't get an error if the connection was lost. Rather, I'd get a zillion dialog boxes saying "Disk not initalized". Mind, this is a Access error, and not a VB error so I'm not even sure if this can be trapped as well.

Insights?
 

Users who are viewing this thread

Back
Top Bottom