473,405 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Dir() Error 52: Bad file name or number

1,287 Expert 1GB
I'm using

Expand|Select|Wrap|Line Numbers
  1. strFileName = "\\serverName\folderName\fileName.txt"
  2. If Dir(strFileName) > "" Then
  3. ...
This worked fine for me, even when I disconnected from the network, but when a user ran it on an unconnected laptop the Dir line threw an Error 52: Bad file name or number. It seems like Dir should just return an empty string instead of an error in any case.

Anyone know why it would do that?
Feb 6 '09 #1
3 29499
ADezii
8,834 Expert 8TB
@ChipR
This appears to be the Default Behavior for Network Paths, just set a
Trap for Error Number 52 as in
Expand|Select|Wrap|Line Numbers
  1. On Error GoTo Err_Test_Click
  2. strFileName = "\\serverName\folderName\fileName.txt"
  3.  
  4. If Len(Dir(strFileName)) > 0 Then
  5.   'File/Path OK, code execution begins here
  6. Else
  7.   'don't really need this, an Error will be generated
  8. End If
  9.  
  10. Exit_Test_Click:
  11.   Exit Sub
  12.  
  13. Err_Test_Click:
  14.   If Err.Number = 52 Then   'Bad File Name or Number
  15.     MsgBox "File or Network Path not found!"
  16.   Else
  17.     MsgBox Err.Description, vbExclamation, "Error in Test_Click()"
  18.   End If
  19.     Resume Exit_Test_Click
Feb 6 '09 #2
ChipR
1,287 Expert 1GB
Thanks ADezii, I did that to handle the error, but I was surprised by what seems to me to be an undocumented error result. It worries me about what other errors could magically pop up that I can't possibly forsee, but I guess I'll just have to fix them quick when they happen.
Feb 6 '09 #3
ADezii
8,834 Expert 8TB
@ChipR
Do not despair, ChipR, for here is a clean and efficient alternative:
Expand|Select|Wrap|Line Numbers
  1. 'Must set a Reference to the Microsoft Scripting Runtime
  2. Dim fso As FileSystemObject
  3. Dim fil As File
  4.  
  5. Set fso = New Scripting.FileSystemObject
  6.  
  7. If fso.FileExists("\\serverName\folderName\fileName.txt") Then
  8.   'code execution here
  9. Else
  10.   MsgBox "File and/or Path cannot be found", vbCritical, "File Not Found"
  11. End If
  12.  
Feb 7 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Victoria Chin | last post by:
Could someone point me in the right direction? I've migrated three FrontPage 2002 websites to a new web server. Each web site has a Access 2000 database on the data server. I have the global.asa...
12
by: Mike Brashars | last post by:
Hi all, I have been searching for a week and am unable to find and example to "Populate picklist from directory and return file name". I have a php script that reads a log file and plots a...
6
by: Jchick | last post by:
Can anyone give me a clue to build a VB.NET program to take a file name that looks like this: $_1234_99999999_7777777777_00000000_$_A.tif And make it into a CSV file to look like this: ...
0
by: kalyanijala | last post by:
Hi There, I have a problem running a VB program. This programs actually reads a DAT file and gives the best CPU time taken to run the program. for example I'm reading files like TN3004, TN3104 ,...
1
by: jgscott3 | last post by:
Dear Access Developers: I need to automatically import a file into Access from the same directory every day. However, I need the code to search the files in the directory and only import the...
3
rajiv07
by: rajiv07 | last post by:
Hi to all, I have a script to list the file names in a directory .When i run this script locally (command prompt) it displays the exact file name (even though the file name has two spaces).But i...
185
by: jacob navia | last post by:
Hi We are rewriting the libc for the 64 bit version of lcc-win and we have added a new field in the FILE structure: char *FileName; fopen() will save the file name and an accessor function will...
6
by: vijayarl | last post by:
hi all, i am reading the content of the directory & then putting if condition to comapre the file name. problem is: filename ends with number. eg :prstat-Lvs-20080118-2100 the first part...
0
by: nilesh tayde | last post by:
how can i pass parameter to print access report by giving parameter as Report File Name,Query,PrinterName,Number of copies to be print my code is Function fPrintRemoteReport(strMDB As...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.