Solved

ms/access 2013 open external file

Posted on 2015-02-04
3
534 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 35

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

810 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