Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228

    Using listbox to open file

    Im using the code from this post here:

    http://www.utteraccess.com/forum/Pop...-t1209291.html



    If I dont edit the code at all it tried to open C:/OS, so ive made amendments shown here:


    Code:
    Private Sub Form_Open(Cancel As Integer)
    ' if you want you can also file the files in the relevant drive by passing a file extension to the function poplistbox.
    '1. To list all files in the directory use: PopListBox("YourFolderOrDriveName")
    '2. To list specific files in a diretory use: PopListBox("YourFolderOrDriveName","txt"). To filter by text files. or "xls" ofr excel etc.
    
    With Me.MyListBox
        .RowSource = PopListBox("\\SERVER\general\Documents\!management\VBA_Templates_do_not_modify\")
        .RowSourceType = "value list"
    End With
    
    End Sub
    
    Private Sub MyListBox_DblClick(Cancel As Integer)
    
    On Error Resume Next
    
    Application.FollowHyperlink OpenListItem("Form1", "MyListBox", "\\SERVER\general\Documents\!management\VBA_Templates_do_not_modify\")
    
    
    End Sub
    When using these amendments the code does nothing at all. The hyperlink is correct, Ive made a command button to test:

    Code:
    Private Sub Command5_Click()
    Application.FollowHyperlink ("\\SERVER\general\Documents\!management\VBA_Templates_do_not_modify\")
    
    End Sub
    Ive tried a few things with no luck. Any sugestions appreciated.

    Note: The purpose of the code right now is to open a document from the list. I will later change the code to do some other things.
    Last edited by Homegrownandy; 07-31-2018 at 06:43 AM.

  2. #2
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Code:
    "C:\Users\Documents\test"
    works perfect.

    Its only when i use a server location that it doesnt work. It will show the correct docuemnts but will not open them. (I have tried with the \ and without at the end)

  3. #3
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    What is the code in the OpenListItem function, without seeing that we don't know what it is trying to do?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  4. #4
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    It's in the link provided Minty.

    ive been doing some testing. Its the files themselves that are the problem. If i put a pdf in there or a different word document then it will open. I'll update in a moment.

  5. #5
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    I can open other word documents with the same file extension in the same folder saved on the same word version. Its just these files with bookmarks in that wont open (I dont think thats relevent).

    Will open: 3rd party request.docx
    wont open: RAM_Template - risks insert.docx

  6. #6
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    It was the underscore. Finally figured it out. No idea why that would cause error (or simply not work) but without the underscore it works.

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

Similar Threads

  1. Replies: 6
    Last Post: 09-14-2017, 07:31 AM
  2. Open form from a listbox
    By raphael99 in forum Programming
    Replies: 6
    Last Post: 04-06-2015, 12:00 PM
  3. Replies: 1
    Last Post: 11-28-2014, 06:56 PM
  4. Replies: 18
    Last Post: 03-19-2013, 08:50 AM
  5. Replies: 1
    Last Post: 09-27-2010, 10:10 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