Error 52 finding if Path exists

  • Thread starter Thread starter TonyT
  • Start date Start date
T

TonyT

Hi,

I have one customer with Local Disk being D: or E: on a couple of pc's &
can't change the bootdisk letter designation.

Previously I have checked the existence of a folder using
Len(Dir(C:\FolderName, vbDirectory)) checking for "" if it doesnt exist.

but if I do an If/ElseIf loop to check D & E drives I get an error 52 when a
Drive letter exists (testing on mine D thru K exist as DVD, CDRom, Card
Readers etc.) but isnt a valid Path.

I have tried the fs.fileExists route & that returns the same error +
sometimes the file won't exist but I need to make sure the folder does before
copying the frontend.
 
sorted around for now by using on error resume next around nested if/then's;

strDrive = Dir("D:\FolderName",vbdirectory)
If strDrive = "" Then
strDrive = Dir("E:\FolderName", vbDirectory)
If trDrive = "" Then
strDrive = Dir("C:\FolderName", vbDirectory)
etc etc

very clumsy, but it works :/

oh and also first post should have been checking if Dir(.....) = 0 not ""

TonyT..
 
Thanks Allen,

just gave that a go for FolderExists & just incorporating the GetAttr()
coding, which returns error code '5' for D & E drives, so still needs the
nested If/Thens but looks neater :)

I could simplify the code considerably if the Dir( FolderName, vbDirectory)
function returned the Drive letter rather than just the folder name, is there
any similar function that can?
 
Hi,

I have one customer with Local Disk being D: or E: on a couple of pc's &
can't change the bootdisk letter designation.

Previously I have checked the existence of a folder using
Len(Dir(C:\FolderName, vbDirectory)) checking for "" if it doesnt exist.

but if I do an If/ElseIf loop to check D & E drives I get an error 52 when a
Drive letter exists (testing on mine D thru K exist as DVD, CDRom, Card
Readers etc.) but isnt a valid Path.

I have tried the fs.fileExists route & that returns the same error +
sometimes the file won't exist but I need to make sure the folder does before
copying the frontend.

Hi,

Here is mine which does not fail with Error 52 when drive letter does
not exists:

Function FolderExists2(fName As String) As Boolean
Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")
FolderExists2 = fs.FolderExists(fName)
Set fs = Nothing
End Function

Regards,
Branislav Mihaljev
Microsoft Access MVP
 
thanks again Allen,

Nothing ready written there, but more than enough info for me to cobble
something together using various parts, thought the DriveExists one would
work stand-alone, but will need to combine with other bits on there to
indetify drive type to give boolean IsDriveAHardDrive("D") type functionality.
 
thanks alot, much simpler way & works a treat!!

now just one If/ElseIf statement - result

TonyT..
 
Back
Top