Author: Calvin Smith
http://www.CalvinSmithSoftware.com/codedisk/sneakpeek.htm

The following example demonstrates how a developer can
programmatically have a user select a disk file
from any directory.


'We need the following API declaration first...

Private Type OPENFILENAME
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    lpstrFilter As String
    lpstrCustomFilter As String
    nMaxCustFilter 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

Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long

Const MAX_PATH = 260

Private Sub cmdGetFileName_Click()

On Error GoTo cmdGetFileName_Click_Err

     Dim l As Long
     Dim O As OPENFILENAME

     O.hInstance = 0
     O.hwndOwner = hWnd
     O.lpstrFile = Space$(MAX_PATH)
     O.nMaxFile = MAX_PATH
     O.lStructSize = Len(O)
     l = GetSaveFileName(O)

     '*** If the user cancels, then simply exit
     If (Left$(O.lpstrFile, InStr(O.lpstrFile, Chr$(0)) - 1) = "") Then
         Exit Sub
     Else
         '*** Pass the selected file back to your textbox
         Me!YourTextBox = Left$(O.lpstrFile, InStr(O.lpstrFile, Chr$(0)) - 1)
         Exit Sub
     End If

cmdGetFileName_Click_Exit:
    Exit Sub

cmdGetFileName_Click_Err:
    If Err Then
        'Trap errors here, if any!
        Resume cmdGetFileName_Click_Exit
    End If
End Sub