Results 1 to 2 of 2
  1. #1
    Larryg is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2015
    Posts
    50

    Storing document or link with record

    Hello;



    I'm looking for a way to store a document with a record on an UNbound form. Access 2007. I have an unbound form, and I have a document sitting in a folder. I want to attach or save a link to that document when the record is saved. A link would be preferred in order to save space in the DB. So, the user is completing the form, and there is a document sitting in another folder that I want associated with that record. I want the user to be able to navigate to the correct document (a file like a word or pdf doc) and reference that document in the form, then save the form. Then, at some later date, a user could call that record, populate the fields, including the document reference field, and the user could click the link which would take them to the document, and open it for viewing. I don't need the document to actually be displayed in the form, just allow the user to open the linked document to view. There will be only 1 document linked to any record, and only some records will have documents referenced.

    I have the form working correctly, and the recall thereof working correctly, the linked document function is an add-on functionality. I have created a field in the table with a data type as attachment. However, as I have gathered from some research, this appears to be used for BOUND forms, and only when storing an image document to be viewed within the form, such as a picture within a personnel record. I don't think this is what I need. I just need to store a link, then be able to later call the record and display the document in its native application (most likely a scanned image jpeg document). I need to use a UNC address also, as not all users have the same drive letters for the same folder locations.

    In another piece of research, I came across an old thread in this forum (https://www.accessforums.net/forumdi...ile-31690.html) which seem to be close to what I'm looking for, but the link provided does not open up a post. That could be my answer but I can't view it.

    Can anyone get me to the referenced post, or, provide a working solution to my needs? (I might need both depending on what's in the post I can't see.) I found many posts on the net surrounding this subject, but none seem to be on point with what I need. Most all make use of a BOUND form. I use UNbound forms.

    Thanks...

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Then you want to save the link.
    User can pick the file to save in the textbox

    user picks the file
    Code:
    sub btnSelectFile_click()
       txtFile = UserPick1File("c:\folder\")
    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 11.0 Object Library, in vbe menu, TOOLS, REFERENCES
    '===================
    
    With Application.FileDialog(msoFileDialogFilePicker)   
        .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
    Paste this code into a module, and it will open ANY file in its native application.

    usage: OpenNativeApp ME.txtBox
    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. Replies: 1
    Last Post: 07-07-2016, 12:41 PM
  2. noob.. DB for storing multiple lines in to one record
    By wmarke in forum Database Design
    Replies: 9
    Last Post: 06-18-2015, 02:55 PM
  3. Storing PDF or link to PDF in Access 2010
    By kawi6rr in forum Access
    Replies: 1
    Last Post: 05-30-2014, 02:29 PM
  4. Replies: 5
    Last Post: 01-23-2014, 09:36 AM
  5. Replies: 5
    Last Post: 09-10-2013, 02:52 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