Run-time error '52': Bad file name or number
I would like to ask for your help and suggestions as to why my code encounters a "run-time error '52': bad file name or number" when I am using a computer which do not really have access to the directory drive. I tried it on my personal computer and it showed the run-time error.
My code is working fine when I am using our company computers which have access to the directory drive. And it displays the message box "unable to access" if I try to change the folder name to make it inaccessible (for troubleshooting purposes).
What I am trying to do is actually display a message box just in case the computer used do not have any access to the directory.
I tried searching around, tried using "", 0, and vbNullString. But no success. Thank you in advance for any help.
'Check if all fields are filled up. If Wbb.Sheets("Report").TextBox3.Value = "" Then MsgBox "Please check missing data." Else 'Check if drive is accessible, if not prompt a message If Dir(filePath1, vbDirectory) = "" Then 'this is where the run-time error is pointing at MsgBox "Unable to access drive. Please save file manually." Exit Sub Else 'Check if folders exists in drive. If does not exist, create folders. If filePathCheck <> "" Then aDirs = Split(filePathCheck, "\") If Left(filePathCheck, 2) = "\\" Then iStart = 3 Else iStart = 1 End If sCurDir = Left(filePathCheck, InStr(iStart, filePathCheck, "\")) For i = iStart To UBound(aDirs) sCurDir = sCurDir & aDirs(i) & "\" If Dir(sCurDir, vbDirectory) = vbNullString Then MkDir sCurDir End If Next i End If End If
on error goto ...filePath1contains if the error occurs? The only thing I can think why this error is thrown is iffilePath1contains anUNCpath like "\\Servername\\SharedFolder\Resource\" and this path is not available over the network. It this is true for you, see answers.microsoft.com/en-us/msoffice/forum/….