Results 1 to 2 of 2
  1. #1
    JohnSmith is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2017
    Posts
    7

    Storing and Renaming Files Outside of Access

    I am using Access 2010.


    Regarding storing files (video, image, pdf, etc) in Access.
    I do not want to embed these files to the database.
    The idea is to store these files in another location and rename the file name to my own naming convention.


    I would like functionality like prompting the user to "attach" the file to the record.
    Similar to how you would send an attachment in an email.
    The user would locate the current location of the file to be sent.
    User would then submit the information along with the pertinant information needed on the form.


    On the backend.


    Access would then COPY the file to a designated location of the develper's choosing (another part of the harddrive) and rename the file (developer's file naming convention).
    The only information stored in Access would be the location of the file and new file name in which Access rename it to.


    Just need some guidance on where I should start.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    have a button on a form ,and a textbox: txtFilename (textbox is bound to a field to store the path)
    user clicks button to pick a filename to store in a text box.
    btn click code:
    Code:
    sub btnPickFile_click()
       vRet = UserPick1File("c:\folder\")
       if not IsNull(vREt) then txtFilename   = vRet
    end sub
    put this code into a MODULE for user to pick the file
    Code:
    Public Function UserPick1File(Optional pvPath)
    Dim strTable As String
    Dim strFilePath As String
    Dim sDialog As String, sDecr  As String, sExt As String
    
    '===================
    'YOU MUST ADD REFERENCE : Microsoft Office xx.0 Object Library, in vbe menu, TOOLS, REFERENCES
    '===================
    With Application.FileDialog(msoFileDialogFilePicker)     'msoFileDialogSaveAs
        .AllowMultiSelect = False
        .Title = "Locate a file to Import"
        .ButtonName = "Import"
        .Filters.Clear
         '.Filters.Add "CSV Files", "*.csv"
         '.Filters.Add "Excel Files", "*.xls;*.xlsx"
        .Filters.Add "All Files", "*.*"
        .InitialFileName = pvPath
        .InitialView = msoFileDialogViewList    'msoFileDialogViewThumbnail
        
            If .Show = 0 Then
               'There is a problem
               Exit Function
            End If
        
        'Save the first file selected
        UserPick1File = Trim(.SelectedItems(1))
    End With
    End Function
    users may want to open the document.
    usage:
    Code:
    sub btnOpenFile_click()
      OpenNativeApp ME.txtBox
    end sub
    Paste this code into the module too, once you save the path,
    This code will open ANY file in its native application.
    In a form put the field and a button to open it.
    if the file is myFile.pdf, will open it in acrobat
    if the file is myFile.doc, it will open the doc in Word
    if its just a file path, it will open in file explorer.
    etc..

    Code:
    'Attribute VB_Name = "modNativeApp"
    'Option Compare Database
    Option Explicit
    
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
    
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    Const SW_SHOWNORMAL = 1
    Const SE_ERR_FNF = 2&
    Const SE_ERR_PNF = 3&
    Const SE_ERR_ACCESSDENIED = 5&
    Const SE_ERR_OOM = 8&
    Const SE_ERR_DLLNOTFOUND = 32&
    Const SE_ERR_SHARE = 26&
    Const SE_ERR_ASSOCINCOMPLETE = 27&
    Const SE_ERR_DDETIMEOUT = 28&
    Const SE_ERR_DDEFAIL = 29&
    Const SE_ERR_DDEBUSY = 30&
    Const SE_ERR_NOASSOC = 31&
    Const ERROR_BAD_FORMAT = 11&
    
    
    Public Sub OpenNativeApp(ByVal psDocName As String)
    Dim r As Long, msg As String
    
    r = StartDoc(psDocName)
    If r <= 32 Then
        'There was an error
        Select Case r
            Case SE_ERR_FNF
                msg = "File not found"
            Case SE_ERR_PNF
                msg = "Path not found"
            Case SE_ERR_ACCESSDENIED
                msg = "Access denied"
            Case SE_ERR_OOM
                msg = "Out of memory"
            Case SE_ERR_DLLNOTFOUND
                msg = "DLL not found"
            Case SE_ERR_SHARE
                msg = "A sharing violation occurred"
            Case SE_ERR_ASSOCINCOMPLETE
                msg = "Incomplete or invalid file association"
            Case SE_ERR_DDETIMEOUT
                msg = "DDE Time out"
            Case SE_ERR_DDEFAIL
                msg = "DDE transaction failed"
            Case SE_ERR_DDEBUSY
                msg = "DDE busy"
            Case SE_ERR_NOASSOC
                msg = "No association for file extension"
            Case ERROR_BAD_FORMAT
                msg = "Invalid EXE file or error in EXE image"
            Case Else
                msg = "Unknown error"
        End Select
    '    MsgBox msg
    End If
    End Sub
    
    
    Private Function StartDoc(psDocName As String) As Long
    Dim Scr_hDC As Long
    
    Scr_hDC = GetDesktopWindow()
    StartDoc = ShellExecute(Scr_hDC, "Open", psDocName, "", "C:\", SW_SHOWNORMAL)
    End Function

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

Similar Threads

  1. Storing Access Files in OneDrive
    By ebbolles in forum Misc
    Replies: 1
    Last Post: 06-30-2015, 12:46 AM
  2. Renaming Files in a Folder
    By Jen in forum Modules
    Replies: 5
    Last Post: 06-01-2015, 04:55 PM
  3. Storing and Attaching pdf Files
    By EddieN1 in forum Database Design
    Replies: 4
    Last Post: 02-19-2015, 07:09 AM
  4. Renaming Files using data from a table or query
    By enzokevin in forum Programming
    Replies: 7
    Last Post: 10-17-2014, 05:42 AM
  5. Replies: 7
    Last Post: 08-27-2012, 10:28 AM

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