Test for Existance of Network Drive

  • Thread starter Thread starter Mike Thomas
  • Start date Start date
M

Mike Thomas

In Access 200, VBA code, is there a way to test for the existance of a
network drive which may or may not have been mapped to the current Windows
session?

Many thanks
Mike Thomas
 
Hi Mike,

You could try using the FileSystemObject (Windows Scripting library -
scrrun.dll). If you know the UNC path of the network drive you could pass
it to the GetFolder function of the FileSystemObject. You will need some
simple error handling to trap file errors (I have included a sample in the
code below). There may be better ways to do this, but I hope this helps
just the same.

Private Sub Command0_Click()
On Error GoTo ErrHandler
Dim fso As New FileSystemObject
Dim fldr As Folder
Dim strUNCpath As String

strUNCpath = "\\MyServer\MyShare\FolderName"

Set fldr = fso.GetFolder(strUNCpath)
If fso.FolderExists(fldr) Then
MsgBox "Folder exists!"
End If

Exit_Command0_Click:
Exit Sub

ErrHandler:
Select Case Err
Case 76 'File not found
MsgBox "Folder does not exist!"
Case Else
MsgBox Err.Number & ": " & Err.Description
End Select
Resume Exit_Command0_Click

End Sub


Jamie



Jamie
 
Back
Top