Results 1 to 10 of 10
  1. #1
    mcaliebe is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2017
    Posts
    18

    Browse for file and save in default directory

    I have a form which I am using to set up details for new parts. I want the ability to browse for a drawing on my hard drive, once located, copy it to the default drawing folder that will remain with the database.


    I will also need to save the file name in the details table so I can reopen it when necessary.

    Can someone offer a suggestion?

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  3. #3
    mcaliebe is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2017
    Posts
    18
    I don't see this working. There is nothing in the database about browsing for a file. I need the ability to brows for a file, and save it in the default directory of the database. As well, I need to record the file name so it can be retrieved when the record is brought back up.

    I found the code to fire off the file picker, and it will return the path of the file in its current location, however I need to do the following with the file

    File path: "C:\somedirectory\file.pdf

    Copy file.pdf to my default directory "C:\MyDatabase\MyStoredFiles"
    Record the file name "file.pdf" to my table

  4. #4
    Paul1 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    50
    You can browse for a file using the Application.FileDialog(msoFileDialogFilePicker) function from the office library.
    See http://www.minnesotaithub.com/2013/0...cess-with-vba/

  5. #5
    mcaliebe is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2017
    Posts
    18
    Quote Originally Posted by Paul1 View Post
    You can browse for a file using the Application.FileDialog(msoFileDialogFilePicker) function from the office library.
    See http://www.minnesotaithub.com/2013/0...cess-with-vba/
    Yes- I have this in my module to open and pick a file name, but I don't know how to copy or upload it to the database directory which I will store these files in.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    mcaliebe,
    Sorry for the link I provided. It was the starting link to a thread dealing with images and the file system. It is not really relevant to your needs.

    The link provided by Paul1 handles the file dialog.
    A Link to move/copy a file to a specific directory

    Good luck.

  7. #7
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by mcaliebe View Post
    I have a form which I am using to set up details for new parts. I want the ability to browse for a drawing on my hard drive, once located, copy it to the default drawing folder that will remain with the database.
    I will also need to save the file name in the details table so I can reopen it when necessary.

    Can someone offer a suggestion?
    Maybe this will help.

    Step 1: Orange and Paul1 have provided links to code to select a file. Use a file picker and save the path and file name to a variable.
    Step 2: Hard code the default drawing folder or use the folder picker to select the folder to save the file into (use a variable).

    The rest is all in code...

    Step 3: Use the "FileSystemObject.CopyFolder" command to copy the file to the default drawing folder
    Step 4: Insert a new record or update a current record with the file name (and the path).


    All of these step would/could be in one sub.... in a button click event....

  8. #8
    mcaliebe is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2017
    Posts
    18
    Thanks fore everyone's help. I was able to use the information here to provide a viable solution.

  9. #9
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  10. #10
    mcaliebe is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2017
    Posts
    18
    These are the two functions I used. I still need to refine them to add the error traps as well as verification of copy and some feedback, but the process is working.
    Code:
    Function selectFile()
    Dim fd As FileDialog, FileName As String
    Dim PrintPath As String
    Dim PrintItem As String
    Debug.Print
    
     
    On Error GoTo ErrorHandler
     
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
     
    fd.AllowMultiSelect = False
     
    If fd.Show = True Then
        If fd.SelectedItems(1) <> vbNullString Then
            FileName = fd.SelectedItems(1)
        End If
    Else
        'Exit code if no file is selected
        End
    End If
     
    'Return Selected FileName
    selectFile = FileName
    PrintPath = GetDBPath & "Prints\"
    PrintItem = Forms!frmItemDetail!txtItemNbr
    Call CopyFile(FileName, PrintPath, PrintItem)
    Set fd = Nothing
    Exit Function
     
    ErrorHandler:
    Set fd = Nothing
    MsgBox "Error " & Err & ": " & Error(Err)
     
    End Function
     
     Function CopyFile(FullFileName, ToFolderName, PartID)
    '' requires reference to Microsoft Scripting Runtime Library
        Dim db          As DAO.Database
        Dim rs          As DAO.Recordset
        Dim td          As DAO.TableDef
        Dim fs          As Scripting.FileSystemObject
        Dim folder      As Scripting.folder
        Dim file        As Scripting.file
        Dim FileName    As String
        Dim FileFolder  As String
    Debug.Print
    'On Error GoTo Err_Proc
        Set db = CurrentDb()
        Set fs = CreateObject("Scripting.FileSystemObject")
        FileName = Mid(FullFileName, InStrRev(FullFileName, "\") + 1)
       
        fs.CopyFile Source:=FullFileName, Destination:=ToFolderName
    Forms!frmItemDetail!txtPrint = FileName
    Forms!frmItemDetail!txtPrintPath = FullFileName
    
    '     Open recordset which will be used to add rows
    '    Set td = db.TableDefs!tblRefDocs
    '    Set td = db.TableDefs!tblTempItemDetails
    '    Set rs = td.OpenRecordset(dbOpenDynaset, dbSeeChanges)
    '        add to reference docs table
    '            rs.AddNew
    '                rs!PartID = PartID
    '                 rs!Print = FileName
    '                rs!FolderName = FileFolder
    '                rs!UpdatedBy = Forms!frmLogin!txtNetworkID
    '                rs!UpdatedDT = Now()
    '                rs!LoggedDate = Now()
    '
    '            rs.Update
    End Function

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Browse to a File and Save Path in a Text Field
    By PSSMargaret in forum Access
    Replies: 2
    Last Post: 03-27-2017, 08:05 AM
  2. Replies: 4
    Last Post: 01-24-2016, 07:41 PM
  3. Browse buttons that save file path into field
    By Zandia in forum Import/Export Data
    Replies: 1
    Last Post: 06-04-2014, 02:55 PM
  4. Replies: 5
    Last Post: 02-03-2014, 03:06 AM
  5. save folder to another directory
    By focosi in forum Programming
    Replies: 7
    Last Post: 08-30-2011, 07:22 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums