• Create a button to browse for files

    Author
    Topic
    #351674

    How can I create a button on an Access form that will open a browse for file dialog?
    I then need the chosen file path to be inserted into a hyperlink field.

    Viewing 2 reply threads
    Author
    Replies
    • #509791

      Sorry, but the only way to use the open file dialog is either to use a direct call to the Windows CommonDialog through the WinAPI or to use the CommonDialog control. There really isn’t any easy way to do it in the current versions of Access.

      • #509809
        Private Sub Command0_Click()
        '
        'I would not consider this to be "easy", so Charlotte's comment is valid.  But here's
        ' a way to do it.
        
        'You need a reference set to Excel for this to work.
        '
        Dim xl As Excel.Application
        Dim str
        '
        'A new instance of excel will open
        '
        Set xl = New Excel.Application
        '
        'It has to be visible for the Dialogue to appear
        '
        xl.Visible = True
        
        '
        'Excel's GetOpenFilename method returns a string of the path and file name you select.
        ' If you do not select a file, it returns "False"
        '
        str = xl.GetOpenFilename()
        MsgBox str
        
        '
        'Be sure to quit excel or it will continue to run in the background.
        '
        xl.Quit
        Set xl = Nothing
        
        '
        'Hope this helps!
        '
        
        End Sub
        
        • #509865

          Nice workaround! I use a class based on the WinAPI, but on a machine with adequate resources, this should work without the headaches of API calls. I’ll have to try it sometime.

    • #509816

      http://www.mvps.org/access/api/api0001.htm

      Code courtesy of:’ Microsoft Access 95 How-To’ Ken Getz and Paul Litwin
      ‘ Waite Group Press, 1996

      It has code for an API call that has, thus far, worked great for my application.

      Good luck.

    • #509850

      Edited by charlotte on 01/01/10 03:52.

      I changed your addresses to hyperlinks. Click on!–Charlotte

      I also agree with Charlotte’s not easy comment. The most useful demonstration I have seen is in a Candace Tripp demo database called Backup Database (130Kb download) at ftp://www.athree.com/pub/candace/candace/backup/bkup2.zip%5B/url%5D – Access2 version
      ftp://www.athree.com/pub/candace/candace/backup/bkup97.zip%5B/url%5D – Access97 version

      There is a whole lot more than what you are requiring but it can be built from selected components in that file.

      Have a look at the site where it all sits for all sorts of useful downloads
      http://www.candace-tripp.com/_pages/HTML/default_HTML.htm%5B/url%5D

      The hyperlinking is a simple one liner once you have the string containing the path to the file. An example is shown below
      Me.lblFldr.HyperlinkAddress = PthNam
      where Me.lblFldr is the name of the control which is hyperlinked and PthNam is the string to it.

    Viewing 2 reply threads
    Reply To: Create a button to browse for files

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: