Results 1 to 3 of 3
  1. #1
    alikona is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2019
    Posts
    15

    Issues extracting file names that contain a comma

    Hi all,

    I have a mock attachments field on my form. In basic terms, the user can drag/drop a file to 'attach it', access saves the file into a folder generated by that record and the listbox is updated with a hyperlink to that newly saved file.

    Works great, unless there is a comma in the file name. As you can see in the images I've attached, if I rename the file to "testing, file name" I get the results "testing" which creates a broken hyperlink and throws an error when you try to open it.



    I've not entirely sure how to fix this. Any ideas?

    Code:
    Private Sub btRefreshList_Click()
    
    
        Dim sFolder As String
        Dim sBackEnd As String
        Dim FileName As String
        
        sBackEnd = Left(FGetBackEndPath, InStrRev(FGetBackEndPath, "\") - 1)
        sFolder = sBackEnd & sAttachmentFolderName & "\" & Order & "\"
                
            Me.cboAttachments.RowSource = ""
            FileName = Dir(sFolder, vbNormal)
            Do While Len(FileName) > 0
            Me.cboAttachments.AddItem FileName
            FileName = Dir()
            Loop
            
    End Sub


    Attached Thumbnails Attached Thumbnails with comma.PNG   without comma.PNG  
    Last edited by alikona; 04-05-2022 at 11:32 AM. Reason: Forgot to add the images.

  2. #2
    alikona is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2019
    Posts
    15
    I guess I just needed to eat lunch to make my brain work lol

    I've updated my code, enclosing the FileName string in """ quotes and it works as expected.

    Code:
    Private Sub btRefreshList_Click()
    
    
        Dim sFolder As String
        Dim sBackEnd As String
        Dim FileName As String
        
        sBackEnd = Left(FGetBackEndPath, InStrRev(FGetBackEndPath, "\") - 1)
        sFolder = sBackEnd & sAttachmentFolderName & "\" & Order & "\"
                
            Me.cboAttachments.RowSource = ""
            FileName = """" & Dir(sFolder, vbNormal) & """"
            Do While Len(FileName) > 0
            Me.cboAttachments.AddItem FileName
            FileName = Dir()
            Loop
    End Sub

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Thanks for updating the thread with your solution!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Extracting initials from names
    By taryn in forum Queries
    Replies: 8
    Last Post: 02-11-2021, 08:37 AM
  2. Replies: 2
    Last Post: 07-22-2018, 02:44 PM
  3. Replies: 1
    Last Post: 11-23-2017, 03:22 PM
  4. Field Names and VBA issues
    By autiger58 in forum Access
    Replies: 5
    Last Post: 07-05-2016, 09:36 PM
  5. Replies: 5
    Last Post: 02-20-2011, 08:22 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