Solved

ms/access 2013 open external file

Posted on 2015-02-04
3
480 Views
Last Modified: 2016-02-11
I need to open an external file in MS/ACCESS 2013. The user needs to brows on the computer, opened the file (a standard ms/office file e.g. word, excel, ppt) or a PDF / picture and, upon selection, I need to change its name and store in a common folder, albeit keeping its extension for further opening.
Ideally this should be embedded in a control, but its OK to open on a separate window, as long as I get the full path for the file to store it on a database record.
how do I do it?
0
Comment
Question by:jirdeaid
3 Comments
 
LVL 47

Assisted Solution

by:Dale Fye (Access MVP)
Dale Fye (Access MVP) earned 250 total points
Comment Utility
I use the following function to browse and select a file name.  The function arguments provide a method for changing the title of the box, identifying specific file types, and identifying whether to allow selection of one or more files.

Public Function GetFile(Optional Title As String = "", _
                        Optional DefaultPath As String = "C:\", _
                        Optional FileTypes As String, _
                        Optional MultiSelect As Boolean = False) As String

    Dim fd As Object
    Dim strFileTypes() As String, intLoop As Integer
    
    Set fd = FileDialog(3)  'msoFileDialogFilePicker
    With fd
    
        .Title = IIf(Title = "", "Select a file", Title)
       ' .RestoreDirectory = False

        'Allow for multiple filetypes in the FileTypes string
        strFileTypes = Split(FileTypes, ";")
        For intLoop = LBound(strFileTypes) To UBound(strFileTypes)
            If Trim(strFileTypes(intLoop)) = "Access" Then
                .Filters.Add "Microsoft Access", "*.mdb;*.mda;*.mde;*.accdb;*.accda;*.accde"
            ElseIf Trim(strFileTypes(intLoop)) = "Excel" Then
                .Filters.Add "Microsoft Excel", "*.xl*;*.xls*"
            ElseIf Trim(strFileTypes(intLoop)) = "Text" Then
                .Filters.Add "Text", "*.txt;*.csv"
            End If
        Next
        
        'If no file type is designated, use *.*
        If UBound(strFileTypes) = -1 Then .Filters.Add "Any file type", "*.*"
        
        .AllowMultiSelect = MultiSelect
        .InitialView = 2        'msoFileDialogViewDetails
        
        'Display the popup and process the return
        If .Show = 0 Then
            GetFile = ""
        Else
            For intLoop = 1 To .SelectedItems.Count
                If GetFile = "" Then
                    GetFile = .SelectedItems(intLoop)
                Else
                    GetFile = GetFile & ";" & .SelectedItems(intLoop)
                End If
            Next
        End If
    End With
    
    Set fd = Nothing
        
End Function

Open in new window

0
 
LVL 34

Accepted Solution

by:
PatHartman earned 250 total points
Comment Utility
Here's a link to the MSOFileDialogFilePicker.  It is supported as early as A2003.  There are also other options such as MSOFileDialogFolderPicker when you want just a folder.

https://msdn.microsoft.com/en-us/library/office/aa195878(v=office.11).aspx

Save the full filename selected using the dialog in your table.  Use the FollowHyperlink method to open the file.

https://msdn.microsoft.com/en-us/library/office/ff822080(v=office.15).aspx

Using the FollowHyperlink method will allow Access to open ANY file type that is defined to windows so that it knows what program to open.  So essentially, if you can double-click on the file in Windows Explorer and have the correct program open, then FollowHyperlink will do the same thing.  This method also allows you to open web pages and your email client.
0
 

Author Closing Comment

by:jirdeaid
Comment Utility
Thanks a lot for both! (and for the very prompt answer. As a matter of fact I am using Dale's function and Pat's followlink....
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now