Ciao Gianni....
crea un modulo nuovo e incolla il seguente codice:
Public Const OFN_FILEMUSTEXIST = &H1000
Public Const OFN_HIDEREADONLY = &H4
Public Const OFN_PATHMUSTEXIST = &H800
Public Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustomFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Public Declare Function GetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" (lpofn As OPENFILENAME) As Long
Public Sub ShowFile(frm As Form, fb As OPENFILENAME)
Dim fName As String
Dim result As Long
Dim path As String
path = "C:\"
With fb
.lStructSize = Len(fb) 'Size of the structure
.hwndOwner = frm.Hwnd 'Handle to window opening the dialog
.hInstance = 0 'Handle to calling instance (not
needed)
.lpstrFilter = "Tutti i file (*.*)" & vbNullChar & "*.*" &
vbNullChar _
'.lpstrCustomFilter is ignored -- unused string
.nMaxCustomFilter = 0
.nFilterIndex = 1 'Default filter is
the first one (Text Files, in this case)
.lpstrFile = Space(256) & vbNullChar 'No default
filename. Also make room for received path and _
filename of the
user's selection.
.nMaxFile = Len(.lpstrFile)
.lpstrFileTitle = Space(256) & vbNullChar 'Make room for
filename of the user's selection
.nMaxFileTitle = Len(.lpstrFileTitle)
.lpstrInitialDir = path & vbNullChar 'Initial directory
is C:\
.lpstrTitle = "Scelta File" & vbNullChar 'Title of file
dialog
.flags = OFN_PATHMUSTEXIST Or OFN_FILEMUSTEXIST Or
OFN_HIDEREADONLY
.nFileOffset = 0 'The rest of the
options aren't needed.
.nFileExtension = 0
'.lpstrDefExt is ignored -- unused string
.lCustData = 0
.lpfnHook = 0
'.lpTemplateName is ignored -- unused string
End With
result = GetOpenFileName(fb)
If result <> 0 Then
fName = Left(fb.lpstrFile, InStr(fb.lpstrFile, vbNullChar) -
1)
End If
End Sub
Ora all'inizio del codice (subito dopo Option Compare Database) della
maschera che contiene il pulsante incolla:
Dim fb As OPENFILENAME
Dim RetVal As Long
Adesso incolla questo codice sull'evento "clic" del pulsante della
maschera che ti aprirà la finestra di ricerca file:
Call ShowFile(Me, fb)
fName = Left(fb.lpstrFile, InStr(fb.lpstrFile, vbNullChar) - 1)
Me.tuocampo = fName
Saluti
M7a1x