Application.FileSearch on Server 2008 R2

T

TomT

I am using VBA (in an MS Access 2003 app) to use Application.FileSearch to
locate a user's Acrobat Reader executable. I have developed this and tested
on a Win 7 x64 machine, and it works perfectly. However when I test it on a
Windows 2008 R2 system I get a very odd behavior.

In the code, I use environment variables to find the location of Program
Files, and build a string for the .LookIn property of the
Application.FileSearh.NewSearch object.

Here is the code:

Public Function FindAcrobatReader() As String
On Error GoTo Err_FindAcrobatReader
' Comments :
' Parameters :
' Created : 2/8/2010 1:04:28 PM
' Modified :
' Returns :
' --------------------------------------------------

Dim i As Integer
Dim acrobatFileAndPath As String

acrobatFileAndPath = GetEnvironVar("ProgramFiles")
acrobatFileAndPath = acrobatFileAndPath & "\Adobe"

With Application.FileSearch

.NewSearch
.LookIn = acrobatFileAndPath
.SearchSubFolders = True
.FileName = "AcroRd32.exe"
.MatchTextExactly = True
.filetype = msoFileTypeAllFiles

End With

With Application.FileSearch

If .Execute() > 0 Then

For i = 1 To .FoundFiles.Count

FindAcrobatReader = .FoundFiles(i)

Next i

Else

MsgBox "There were no files found."

End If

End With

'Error Handler
Exit_FindAcrobatReader:
Exit Function

Err_FindAcrobatReader:
If Err.Number <> 0 Then
Select Case Err.Number

Case Else
MsgBox "Error:" & Err.Number & vbCrLf & Err.Description,
vbCritical, "FindAcrobatReader Error"
End Select
End If
Resume Exit_FindAcrobatReader
End Function

On the Server system, (even if I hardcode in the .LookIn path), the .LookIn
always resets itself to my documents folder (e.g. c:\userst\tomt\documents),
and of course the file I'm looking for is not there.

I'm guessing this has something to do with Server 2008 R2 security, but I
don't know what to look for, or where.

Any help would be greatly appreciated
 
C

Colbert Zhou [MSFT]

Hello,

When you start Access in Server 2008, have you tried right click the .exe
application file and choose "Run As Adminitrator" option? When run as
adminitrator, Access VBA codes will have desired right to access C:\Program
Files folder.

Otherwise, you can disable the UAC to get the same effect.


Best regards,
Ji Zhou
Microsoft Online Community Support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top