none
Access 2010 -automodify hyperlink to a specific file (.pdf)

    Question

  • We are trying to modify our Access 2010 Mail database with in-/outbound Mail, by hyperlinking to the specific PDF-files. The base directory ("\\SharedFiles\MailJournal") contains the Inbound / Outbound Folders.
    From the Form, when making a new entry, we want the HyperLink-cell to open the right Folder (ie. not file -but ("//SharedFiles\MailJournal") - so that the user can point at the correct specific PDF-file (eg. Snr208.PDF) in that Folder and then Access will update and autosave the HyperLink to the selected PDF-file.

    The Form Hyperlink will (after enrtry completion) open the specific PDF-file.

    From the Form Hyperlink-cell;  how do we get Access to:
    1- open the correct Folder ("\\SharedFiles\MailJournal")
    2- autosave the adjusted Hyperlink in the same Form-cell to the selected PDF-file link: "\\SharedFiles\MailJournal\Snr208.PDF"

    I'm not a VBA-specialist - so pls. try to make it a simple as possible :)

    Thanks for contributions!

    
    
    
    

    • Edited by LKJohnsen Wednesday, April 03, 2013 12:13 PM
    Wednesday, April 03, 2013 12:05 PM

Answers

  • ad. 1

    text file on form where you store hiperlink

    ad.2

    You can extend filter in filedialog:

    Private Sub Link_til_saksdokument_Click()
        Dim fDialog     As Office.FileDialog
        Dim varFile     As Variant
    
        Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
        With fDialog
            .AllowMultiSelect = False
            .InitialFileName = "\\SRV-2\Mail Journal\"
            .Title = "Choose file"
            .Filters.Clear
            .Filters.Add "PDF-files", "*.PDF"
            .Filters.Add "MSG-files", "*.msg"
            .Filters.Add "All files", "*.*"
            If .Show = True Then
                Me.pathtopdf = "#" & fDialog.SelectedItems(1) & "#"
            End If
        End With
    End Sub


    Michał

    Wednesday, April 03, 2013 1:24 PM
    1. Add button on form
    2. go to properties Events -> On Click add [event procedure] cllick button: ...
    3. In vbe editor Tools->references
    4. Check Microsoft Access 14.0 Object Library click OK

      5. Add code in event procedure:

        Dim fDialog     As Office.FileDialog
        Dim varFile     As Variant
    
        Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
        With fDialog
            .AllowMultiSelect = False
            .InitialFileName = "\\SharedFiles\MailJournal\*.dbf"
            .Title = "Choose file"
            .Filters.clear
            .Filters.Add "PDF-files", "*.PDF"
            If .Show = True Then
                Me.pathtopdf = "#" & fDialog.SelectedItems(1) & "#"
            End If
        End With

    Thats all!

    Aaaa, I forgot the text field must be named "pathtopdf"


    Michał

    Wednesday, April 03, 2013 12:37 PM

All replies

    1. Add button on form
    2. go to properties Events -> On Click add [event procedure] cllick button: ...
    3. In vbe editor Tools->references
    4. Check Microsoft Access 14.0 Object Library click OK

      5. Add code in event procedure:

        Dim fDialog     As Office.FileDialog
        Dim varFile     As Variant
    
        Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
        With fDialog
            .AllowMultiSelect = False
            .InitialFileName = "\\SharedFiles\MailJournal\*.dbf"
            .Title = "Choose file"
            .Filters.clear
            .Filters.Add "PDF-files", "*.PDF"
            If .Show = True Then
                Me.pathtopdf = "#" & fDialog.SelectedItems(1) & "#"
            End If
        End With

    Thats all!

    Aaaa, I forgot the text field must be named "pathtopdf"


    Michał

    Wednesday, April 03, 2013 12:37 PM
  • Thanks Michal - for your rapid response!

    Seems OK and simple - but a couple of questions:

    -which text field?  : must be "pathtopdf"

    -Tested your code in event procedure and it respons "compile error" - at the line : Me.pathtopdf =

    Private Sub Link_til_saksdokument_Click()
        Dim fDialog     As Office.FileDialog
        Dim varFile     As Variant
    
        Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
        With fDialog
            .AllowMultiSelect = False
            .InitialFileName = "\\SRV-2\Mail Journal\"
            .Title = "Choose file"
            .Filters.Clear
            .Filters.Add "PDF-files", "*.PDF"
            If .Show = True Then
                Me.pathtopdf = "#" & fDialog.SelectedItems(1) & "#"
            End If
        End With
    End Sub
    What if the file is not a PDF-file - but an Email/Outlook *.msg -  element?

    Again - many thanks

    
    
    
    Wednesday, April 03, 2013 1:17 PM
  • ad. 1

    text file on form where you store hiperlink

    ad.2

    You can extend filter in filedialog:

    Private Sub Link_til_saksdokument_Click()
        Dim fDialog     As Office.FileDialog
        Dim varFile     As Variant
    
        Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
        With fDialog
            .AllowMultiSelect = False
            .InitialFileName = "\\SRV-2\Mail Journal\"
            .Title = "Choose file"
            .Filters.Clear
            .Filters.Add "PDF-files", "*.PDF"
            .Filters.Add "MSG-files", "*.msg"
            .Filters.Add "All files", "*.*"
            If .Show = True Then
                Me.pathtopdf = "#" & fDialog.SelectedItems(1) & "#"
            End If
        End With
    End Sub


    Michał

    Wednesday, April 03, 2013 1:24 PM
  • LK,

    Pathtopdf must be text field or a label on the fomr.  As long as the path is correct, the hyperlink must work.  Window will know by the extension how to open it.  or just change the me.pathtopdf to VarFile.

    this variable will hold your selection.

    

    Wednesday, April 03, 2013 1:27 PM