I'm using WinXP and Access2003 and I'm trying to fill in a list box with a list of PDF files so the user can open relevent drawings, maps, etc. of the facility.
My code is simple (right out of the help files). [LastSlash is a function that returns the filename once found.]
Private Sub FillList()
Dim fs As Variant
Dim i As Long
Dim FileList As String
Dim WholePath As String
FileList = ""
Set fs = Application.FileSearch
DoCmd.Hourglass (True)
Set EditSet = CurrentDb.OpenRecordset("SELECT tblAdmin.AdminID, tblAdmin.AdminPDFPath FROM tblAdmin " _
& "WHERE (((tblAdmin.AdminID)='X'));", dbOpenDynaset, dbSeeChanges)
WholePath = EditSet("AdminPDFPath") & "\" & Me!ztxtSiteID.Value & "\"
With fs
.NewSearch
.LookIn = WholePath
.FileName = "*.pdf"
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
For i = 1 To .FoundFiles.Count
FileList = FileList & LastSlash(.FoundFiles(i)) & ";"
Next i
End If
Me!lstImages.RowSource = FileList
Me!lstImages.Requery
End With
DoCmd.Hourglass (False)
End If
Set EditSet = Nothing
End Sub
The problem is, that if WholePath points to my local drive, as in:
WholePath = "C:\Documents and Settings\talber\Desktop\Current Projects\SW-MSGP\PDF\GUERDO5556FEDER"
or
WholePath = "C:\MSGP\PDF\GUERDO5556FEDER"
it doesn't work all the time (it will occasionally if you manually run it through the code a few times). The execute statement just doesn't find any files, even though they exist in that directory according to explorer.
However, if WholePath points to a network drive, as in:
WholePath = "I:\USERS\Pretreatment\FOG Database\PDF\GUERDO5556FEDER"
or
WholePath = "I:\USERS\Pretreatment\MSGP\PDF\GUERDO5556FEDER"
it works just peachy.
I have beat my head against this all day, now, and am fed up.
Any ideas?
Thanks,
Terry