How to populate to the (list Box) proper documents from C: drive

Radio Fixer 41 Reputation points
2023-03-09T16:22:14.09+00:00

Hello, can you assist me with this? I am not a programmer and have created a simple dropdown that user are selecting, according to their selection on dropdown, system check on their c:\ drive and populate to the (list Box) all documents in that folder. Then user can select the document that are interested to view.

 

Everything is working well but the problem is, it will also show additional hidden files which was removed from the folder. Its mark it as (~$). How can I hide those documents, so List Box does not pick it up?

 

Thank you very much!

User's image

Private Sub ListDoc_Click()
Dim db                  As Database
Dim RS                  As Recordset
Dim sQryString          As String

Dim iSelectedRow


On Error GoTo ErrorHandler
    iSelectedRow = ListDoc.ListIndex

    sMyDoc = ListDoc.Column(0, iSelectedRow)

    sProduct = Right(sMyDoc, Len(sMyDoc) - InStrRev(sMyDoc, "."))
     
        Application.FollowHyperlink sMyDoc
                            
ExitHandler:   'clean up as necessary and exit
   Set RS = Nothing  'These two lines are just an example
   Set db = Nothing  'your code may not include them
   Exit Sub
ErrorHandler:
   Select Case Err  'specific Case statements for errors we can anticipate, the "Else" catches any others
     Case 2501       'Action OpenReport was cancelled.
       MsgBox "No data to display"
       DoCmd.Hourglass False
       Resume ExitHandler
     Case Else
       MsgBox Err.Description
       DoCmd.Hourglass False
       Resume ExitHandler
   End Select
End Sub


Private Sub ListFolders_Change()
Dim iSelectedRow

    txtFolderSearch.Enabled = True
    txtGlobalSearch.Value = ""
    
    iSelectedRow = ListFolders.ListIndex
    
    sFolder = ListFolders.Column(0, iSelectedRow) & "\"

    GetListFolders FileSystem.GetFolder(sSelectDrive & "\" & sFolder)
    
    ListDoc.Enabled = True
    ListDoc.Visible = True
End Sub



Private Sub ListFolders_Click()
Dim iSelectedRow
    ListDoc.RowSource = ""
    iSelectedRow = ListFolders.ListIndex

    sDrive = ListFolders.Column(0, iSelectedRow) & "\"
    
End Sub
Access Development
Access Development
Access: A family of Microsoft relational database management systems designed for ease of use.Development: The process of researching, productizing, and refining new or existing technologies.
821 questions
{count} votes

Accepted answer
  1. Viorel 112.1K Reputation points
    2023-03-13T21:15:04.58+00:00

    Try adding an If to GetListFolder procedure:

    Sub GetListFolders(Folder)
       Dim Files
    
       For Each Files In Folder.Files
          strFile = Files.Name
          If Not strFile Like "~$*" Then
             ListDoc.RowSourceType = "Value List"
             ListDoc.ColumnCount = 2
             ListDoc.AddItem Files & ";" & strFile
          End If
       Next
    End Sub
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful