Solved

ms/access 2013 open external file

Posted on 2015-02-04
3
511 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
ID: 40588892
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
ID: 40588916
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
ID: 40590558
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Modern/Metro styled message box and input box that directly can replace MsgBox() and InputBox()in Microsoft Access 2013 and later. Also included is a preconfigured error box to be used in error handling.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

914 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

18 Experts available now in Live!

Get 1:1 Help Now