|
|
Question : Using VBA to check if a network drive is available
|
|
Does anyone know what code to use to check if a mapped network drive is available?
I need to check availability before running replication
Many thanks
|
Answer : Using VBA to check if a network drive is available
|
|
It should validate that it's connected.
If it doesn't you can also validate folders and files within the drive with these...
Function fn_validate_directory(ByVal strPath As String, ByVal bCreate) As Boolean
'Attempt to find a directory. ' Returns TRUE if found, FALSE if not found. ' Returns TRUE if user passed bCreate = True and code created the directory.
Dim fso As FileSystemObject Set fso = CreateObject("Scripting.FileSystemObject")
Select Case fso.FolderExists(fso.GetParentFolderName(strPath)) Case True fn_validate_directory = True Exit Function Case False If bCreate Then fso.CreateFolder (fso.GetParentFolderName(strPath)) fn_validate_directory = True Else fn_validate_directory = False End If End Select
Set fso = Nothing
End Function
Function fn_validate_file(ByVal sFile As String) As Boolean
Dim fso As FileSystemObject Set fso = CreateObject("Scripting.FileSystemObject")
fn_validate_file = fso.FileExists(sFile)
Set fso = Nothing
End Function
|
|
|
|