Buenas!
Ya lo tengo, gracias a sus aportaciones y a la inestimable ayuda de un amigo siempre dispuesto a ayudar, hemos conseguido lo que buscaba. A continuación les detallo el código que finalmente hemos utilizado:
** En un módulo independiente:
Option Compare Database Option Explicit
#If Win64 Then Private Declare PtrSafe Function SearchTreeForFile Lib "imagehlp" (ByVal rootpath As String, ByVal InputPathName As String, ByVal OutputPathBuffer As String) As LongPtr #Else Private Declare Function SearchTreeForFile Lib "imagehlp" (ByVal rootpath As String, ByVal InputPathName As String, ByVal OutputPathBuffer As String) As Long #End If
Public Type udtFileSearch FileToSearch As String InitialPath As String Found As Boolean FullPathFounded As String PathFounded As String End Type Public uFileSearch As udtFileSearch
Function BuscarArchivo() On Error GoTo ErrorHandler Dim strRuta As String
strRuta = String(260, vbNullChar)
' Si no tenemos InitialPath, asumimos C:\ If uFileSearch.InitialPath = "" Then uFileSearch.InitialPath = "C:\" End If
If SearchTreeForFile(uFileSearch.InitialPath, uFileSearch.FileToSearch, strRuta) Then uFileSearch.Found = True uFileSearch.FullPathFounded = Left$(strRuta, InStr(strRuta, vbNullChar) - 1) uFileSearch.PathFounded = Left$(strRuta, InStrRev(strRuta, "\") - 1) Else uFileSearch.Found = False uFileSearch.FullPathFounded = "" uFileSearch.PathFounded = "" End If
ExitProcedure: Err.Clear Exit Function
ErrorHandler: Select Case Err.Number Case 0 Case Else MsgBox "Error " & Err.Number & " - " & Err.Description & vbNewLine & _ "Procedimiento: BuscarArchivo" & vbNewLine & _ "Módulo: " & Application.VBE.ActiveCodePane.CodeModule.Name, vbCritical, "AVISO" Resume ExitProcedure End Select End Function
** Seguidamente, en el campo "DA", en el evento 'después de actualizar' hemos escrito:
uFileSearch.FileToSearch = DA & ".jpg" uFileSearch.InitialPath = "C:\DA" BuscarArchivo If uFileSearch.Found Then Dim rutainicial As String Dim rutatrobat As String Dim temp As String rutainicial = uFileSearch.InitialPath rutatrobat = uFileSearch.PathFounded proveidor = Right$(rutatrobat, Len(rutatrobat) - Len(rutainicial) - 1) temp = "file:///" & uFileSearch.FullPathFounded link = temp Else MsgBox "No encontrado" End If
** Finalmente, para poder visualizar el archivo JPG, hemos creado un botón y en el evento 'al hacer clic' hemos escrito:
Application.FollowHyperlink link
-------
Y ya está!! Funciona muy bien, el campo "proveedor" se rellena con el nombre de la carpeta donde hay el DA, y el botón sirve para abrir el archivo JPG.
Muchas gracias por su ayuda!!
Saludos
|