Check if a Mapped drive is available

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all.
I want to check if the mapped drive is available before running the code.
(e.g drive S:\). Could someone help me, please ?
Thanks.
 
hi,
I want to check if the mapped drive is available before running the code.
(e.g drive S:\). Could someone help me, please ?

Public Function IsPathAvailable(APath As String) As Boolean

On Local Error Goto LocalError

Dim Dummy As String

IsPathAvailable = False
Dummy = Dir(APath)
IsPathAvailable = True

Exit Function

LocalError:
' Maybe more sophisticated error handling needed.
IsPathAvailable = False

End Function

should do it.


mfG
--> stefan <--
 
Many thanks, Stefan.

Stefan Hoffmann said:
hi,


Public Function IsPathAvailable(APath As String) As Boolean

On Local Error Goto LocalError

Dim Dummy As String

IsPathAvailable = False
Dummy = Dir(APath)
IsPathAvailable = True

Exit Function

LocalError:
' Maybe more sophisticated error handling needed.
IsPathAvailable = False

End Function

should do it.


mfG
--> stefan <--
 
Stefan,

Can you explain how this code works? It appears you are expecting and error
from the Dir call. If the path passed to Dir doesn't exist, Dir returns a
zero length string. Also, I have been working with Acces since 97 and don't
recall ever seeing On Local Error. I tried looking it up in Help, but it
doesn't show. Will you be kind enought to illucidate?

On another note, I would suggest using UNC paths if the app is to be
deployed on more than one computer.

I would think that this would work as well:

blnIsGoodPath = Dir(strSomePath) <> ""
 
hi,
Can you explain how this code works? It appears you are expecting and error
from the Dir call. If the path passed to Dir doesn't exist, Dir returns a
zero length string.
Using Dir() with a non-existing drive will throw a run-time error 52.

mfG
--> stefan <--
 
Back
Top