Spidermain50
Spidermain50

Reputation: 689

Access 2000 VBA - Dir() Bad File Name Or Number

I have a scenario where a user who is not on the domain is trying to open a file that is on the network. Trying to determine if the path exists using the Dir() function. Here is what my code looks like...

If Len(Dir("\\xx\xxxxx\Shared\Virtual Machine\_Testing\Update\", vbDirectory)) > 0 Then Return True

I get the Run-Time error Bad file name or number (error number 52).

Upvotes: 1

Views: 2846

Answers (3)

Saravanan
Saravanan

Reputation: 1

Try below steps.

  • Restart your machine
  • After restart, access/open the share path through windows explorer
  • Provide the network credentials and select the option "remember my credentials"

Now run/debug your application. it should work!

Upvotes: -1

ray
ray

Reputation: 8699

For the time-being, if the user doesn't mind mapping a network drive, he could open the file with your code the way it is.

Upvotes: 0

Alex K.
Alex K.

Reputation: 175766

Yep, dir() on a bad/inaccessible unc causes a runtime error, unlike the behaviour for a local file.

You can either wrap it in an error handler or use the GetFileAttributes API and look for the directory attribute flag (the built in getattr() won't work for this).

Upvotes: 4

Related Questions