Here's something I use with great success.  I don't understand most of
it, as I copied it from somewhere, but it works great.


'------------BEGIN CODE---------------------

       Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias
_
         "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

       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

'--------------END CODE -----------------------

And then, in a command button on my form:

'----------------BEGIN CODE FOR COMMAND BUTTON CLICK
PROCEDURE------------------

         Dim lReturn As Long
         Dim sFilter As String
         
         OpenFile.lStructSize = Len(OpenFile)
         OpenFile.hwndOwner = Me.Hwnd
         'OpenFile.hInstance = Application.hInstance
         sFilter = "All Files" & Chr(0) & "*.*" & Chr(0)  'this is where
you can specify what they can look for
         
         OpenFile.lpstrFilter = sFilter
         OpenFile.nFilterIndex = 1
         OpenFile.lpstrFile = String(255, 0)
         OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
         OpenFile.lpstrFileTitle = OpenFile.lpstrFile
         OpenFile.nMaxFileTitle = OpenFile.nMaxFile
         OpenFile.lpstrInitialDir = "My Documents"  'start directory
         OpenFile.lpstrTitle = "Link Document"  'title for dialog box
         OpenFile.flags = 0
         
         lReturn = GetOpenFileName(OpenFile)
         
         If lReturn = 0 Then
           Exit Sub
         Else
            
            Me.txtDocumentPath = Trim(OpenFile.lpstrFile)
            Me.txtDocumentPath = Replace(Me.txtDocumentPath, Chr(0), "")

            
         End If 

'---------------------END OF CODE FOR COMMAND BUTTON CLICK PROCEDURE
--------------------


Hope that helps!

Eric

> -----Original Message-----
> From: [email protected] 
> [mailto:[EMAIL PROTECTED] On Behalf Of lostfayth
> Sent: Monday, January 09, 2006 11:09 AM
> To: [email protected]
> Subject: [AccessDevelopers] Add a file (hyperlink) from a form
> 
> Ok.  I have a Project Tracking Database.  I have a subform 
> called Files with a text box called FileLocation.  
> 
> I want to create a button or an onclick (doesn't matter) so 
> that it automatically opens a window so the user can search 
> for the file on thier hard drive.
> 
> Then when the user selects the file it automatically insert 
> the file location into the text box.
> 
> Any suggestions?
> 
> 
> 
> 
> 
> 
> Please zip all files prior to uploading to Files section. 
> Yahoo! Groups Links
> 
> 
> 
>  
> 
> 
> 



Please zip all files prior to uploading to Files section. 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AccessDevelopers/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to