I am using the code below to populate a listbox. the general idea is to populate the listbox with the path in column(0) and the file name in Column(1) Column (0) will remain hidden and I will use follow hyperlink to open the file.
Code:'------------------------------------------------------------ ' SUBROUTINE NAME: GetFilePathNames() ' PORPOSE: populate a llistbox withe the path and file names ' in a folder ' REQUIRES: A reference to the Microsoft Scripting RunTime ' CREATED BY: Andrew Dulavitz (adulavitz@hotmail.com) ' DATE: January 2024 '------------------------------------------------------------- Private Sub GetFilePathNames() On Error GoTo Err_Handler Dim strFolderPath As String Dim fso As Object ' FileSystemObject Dim fld As Object ' Folder Dim fil As Object ' File Dim i As Integer ' Counter strFolderPath = Me.cboDocumentFolder.Column(2) Me.lstFolderDocs.RowSource = "" ' Clear any previous list items If strFolderPath = "" Then Exit Sub Set fso = CreateObject("Scripting.FileSystemObject") Set fld = fso.GetFolder(strFolderPath) i = 0 'Initialize the counter For Each fil In fld.Files 'Loop through the files in the folder Me.lstFolderDocs.AddItem fil.Path & ";" & fil.Name 'Add the file path and name to the list box i = i + 1 'Increment the counter Next fil 'Me.lstFolderDocs.ListIndex = 0 ' Select the first item in the listbox Exit_Handler: Exit Sub Err_Handler: clsErrorHandler.HandleError "frmCrewInfo", "GetFilePathNames" Resume Exit_Handler End Sub
Everything seems to work as it should until the end result is displayed.
Note the text highlighted in Yellow. It has somehow bled over from the path. This is strange because if I pause he code and type "? fil.Name" in the immediate window I get only the file name. Likewise if I replace fil.Path with some random text string I get to bleed over from that text string. This seems like it should be pretty straightforward but I am quite baffled by this behavior.
Any ideas on what could be going on here?