Results 1 to 4 of 4
  1. #1
    Sonu is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Aug 2019
    Posts
    35

    Hyperlink to a file or an entire folder


    Hello All,


    With the below code, after a click on the form's button, I am able to browse to a default location and save the file location in the text box associated with the form's button.


    But now, I need to incorporate a new functionality in this code. Is it a possibility within this code, when I click on the 'Hyperlink' button on the form, I get a flexibility to either hyperlink a file or an entire folder itself?


    Code:
     Private Sub cmdHyperlink_Click()
    'Open hyperlink dialog box
    
    
        'Declare a variable as a FileDialog object
        Dim fd As FileDialog
        
        'Create a FileDialog object as a File Picker dialog box
        Set fd = Application.FileDialog(msoFileDialogFilePicker)
    
    
        'Declare a variable to contain the path
        Dim sFolder As Variant
    
    
        On Error GoTo Err_cmdHyperlink_Click
        
        'Use a With...End With block to reference the FileDialog object
        With fd
            .InitialFileName = "<Default Folder Path>"
            If .Show = -1 Then ' if OK is pressed
                sFolder = "#" & .SelectedItems(1) & "#"
            End If
        End With
        
        If sFolder <> "" Then ' if a file was chosen
            Me.txtDocLocation = sFolder
            'Me.txtLinkDate = Date
        End If
        
        Set fd = Nothing
        
    Exit_cmdHyperlink_Click:
        Exit Sub
    
    
    Err_cmdHyperlink_Click:
        If Err.Number <> 2501 And Err.Number <> 13 Then
            MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, _
            "sfrmCaseDocs cmdHyperlink_Click"
        End If
        Resume Exit_cmdHyperlink_Click
    
    
    End Sub
    Thank You.

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,398
    you can't with this code as such because you are specifying how the filedialog form behaves with the variable msoFileDialogFilePicker

    If you google 'vba filedialog' you will find all the info you need to understand how this works

    you will see that if you want to pick a folder, you need to do so before the filedialog form is opened. This may suit your requirement, or it may not.




  3. #3
    Sonu is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Aug 2019
    Posts
    35
    Yes you are right. Initially I was able to select a file or even a folder with 'acCmdInsertHyperlink' function. But the problem was that this was not taking me a default folder, so I switched to FileDialog. Now, as you have mentioned I can use FileDialog or FolderDialog but I am looking for a combination of these two.

    Just thinking, if somehow 'acCmdInsertHyperlink' option can be altered so that I can achieve: 1) open a default folder upon button click and 2) select a file or an entire folder.

    Thank you.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    It was recommended in a prior thread to use FollowHyperlink method on your textbox value. Seems like you didn't follow that advice so you're still struggling. At this point, why not have 1 command button to navigate to a folder and 1 to pick a file, storing each in their own respective textboxes. You could hide the folder path textbox and give user the option of navigating to the folder or file using either button.

    Or you can stick with what you have and show the full path in a single textbox. To open to the folder level, in code you'd trim everything off after the last \ using a combination of Right and Len functions. That would give you the folder path. For this, you'd need some way to differentiate which one you want to follow - folder or file path when you FollowHyperlink.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. hyperlink to scan into folder
    By angie in forum Programming
    Replies: 6
    Last Post: 05-29-2019, 01:18 PM
  2. Replies: 1
    Last Post: 06-22-2017, 12:15 PM
  3. Hyperlink to open folder on network
    By angie in forum Forms
    Replies: 3
    Last Post: 12-10-2013, 10:22 AM
  4. Replies: 21
    Last Post: 08-20-2012, 11:59 PM
  5. Access 2010 and HyperLink to Folder
    By grapin in forum Programming
    Replies: 4
    Last Post: 04-13-2012, 01:07 PM

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