Link to home
Start Free TrialLog in
Avatar of MaxwellTurner
MaxwellTurnerFlag for Canada

asked on

Access 2007 - UNC paths in VBA to files on a server (2003)

I have a form in Access 2007.  On Current event, I want to check a directory on a server (running Win 2003) to see if a specific file exists.  If it does, I want to set the Visible property of a hyperlink to True, else False.

If Dir(FileName) = "" Then
        Me!viewpdflink.Visible = False
Else: Me!viewpdflink.Visible = True
End If

Quite  sure the problem is in my path as I can make it work fine if I use a local directory.

FileName = "\\NightWatch\Scans\Contracts\" & Me!Custno & Me!ContractID & ".pdf"

Nightwatch - server name
Scans - shared folder
me!Custno & me!contractid - textboxes on the form that match the filename when combined.

The error I keep getting is:

Run-time error '52':
Bad file name or number

Can someone help me!

Max
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image


FileName = "\\NightWatch\Scans\Contracts\" & Me!Custno & Me!ContractID & ".pdf"

debug.print FileName  'add this line

'that will print the string FIleName on the Immediate window. Copy what was printed and paste here
'or you can check if the string FileName is correctly formatted



If Dir(FileName) = "" Then
        Me!viewpdflink.Visible = False
Else: Me!viewpdflink.Visible = True
End If
Dir() doesn't work with UNC file paths, you'll get that error if the file is not found. I would recommend just handling that error and setting the hyperlink to false when the error is tripped
Check to make sure you have the following identified in your FileName variable.

\\Servername\share name\folder\filename


Also, test it using a Mapped drive letter to see if your code works.

ET
Also, here is another alternative ....

'Set a Reference to the Microsoft Scripting Runtime
Dim fso As FileSystemObject
Set fso = New Scripting.FileSystemObject
 
If fso.FileExists(FileName) Then
  Me!viewpdflink.Visible = True
Else
  Me!viewpdflink.Visible = False
End If


ET
Avatar of MaxwellTurner

ASKER

capricorn1:  it did not print the path on my screen (or anywhere I could see it) but when I debug the error and place my cursor over 'filename' it shows the correct path.

mvasilevsky: ... while I am testing, the file does exist ... it may not always be though, so I see the wisdom in your advice

etsherman: yep, that's what I'm using.

Wish I had done this sooner, but I tried the actual (\\NightWatch\Scans\Contracts\valtes1.pdf) path in Explorer and have found that I cannot access the shared folder.  Also, when I browse my network and try to access NIGHTWATCH, it will not display the shared folders!!??  ...prompts me for username/password ... cannot map a drive either as it won't accept the U/P that I use to log into the server itself.  Very weird because we digitally scan pdf's to that folder from an office MFP all the time without problems.

Seems like I might have permission issues with the server ... maybe, I guess?  I'm the server admin, sort of, but my real IT guy is away on holidays ... anyone have any ideas, or should I post a new question under server 2003.

Max
etsherman:  Tried the second option earlier ... found it via google.  It gives me:

Compile error:
USer-defined type not defined

Not familiar with the code, so I didn't have any idea how to troubleshoot it, so I moved on.  Perhaps this also is related to my inability to access the shared folders on my server from another pc on the network .. ?

Max
Hi Maxwell ....

Check the alternative solution that I posted in my last post.

ET
SOLUTION
Avatar of Eric Sherman
Eric Sherman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Problem solved ... it seems everytime I post a question up here lately, I have to eventually come back in shame because of a silly little thing I over looked!  Doh! lol

To explain, on some worksataions, (including mine) we run a batch file on startup which redirected LPT1 to a shared network printer on the server using NET USE (... because some DOS applications we use could only use LPT1, but using that port on the workstation was not an option).  Someone (ahem, me!) forgot to update these files when our server changed a few months ago, so everytime the workstations started, it ran the batch file using incorrect longin credentials.  Once I updated the batch files, rebooted, I can now see all of the server's shared folders!!  .. and the vba works fine now ... even when the file does not exist!

Thanks guys ... don't know how to handle this question ... I suppose fair will be to give it to Capricorn because he replied first and I'll give the others an assist!

Max

Log on to the server as a user with administrative rights.
Browse to the shared folder, Right click > properties.
Check the security tab.
This should list the users who have access to the folder.
Modify as required.
Leigh.