How not allow file name "THUMBS" appear in a listbox that displays file names

I have a listbox that is populated with file names that exist in a specific directory.

 The onopen event code of the form that puts them there is:

Private Sub Form_Open(Cancel As Integer)

    With Me.ListImageFiles 'the name of your listbox
        .RowSource = PopListBox(Me.txtClientImageFolderDataPath)   ' You can leave the ext. out to show all files
        .RowSourceType = "value list"
    End With

    Me.cmdCloseForm.SetFocus

End Sub

Open in new window


Also in the form code is this:

Function PopListBox(strPath As String, Optional FileExtension As String) As String

    Dim MyFso As Object
    Dim MainDir As Object
    Dim MyFile As Object
    Dim LstItems As String, FileProp As String
    Dim NameLength As Integer, InitialNameLength As Integer, TypeLength As Integer, InitialTypeLength As Integer
    Dim x As Integer, y As Integer
    Dim NameSep As Integer, TypeSep As Integer
    Dim Placer As Variant
    On Error Resume Next
    Set MyFso = CreateObject("scripting.FileSystemObject")
    Set MainDir = MyFso.GetFolder(strPath)
    InitialNameLength = 1
    InitialTypeLength = 1
    For Each MyFile In MainDir.Files ' all this in side this loop is to help try and format the columns a bit more uniformly.
        NameLength = Len(MyFile.Name)
        x = IIf(NameLength > InitialNameLength, NameLength, InitialNameLength)
        InitialNameLength = x
        
        TypeLength = Len(MyFile.Type)
        y = IIf(TypeLength > InitialTypeLength, TypeLength, InitialTypeLength)
        InitialTypeLength = y
    Next
    For Each MyFile In MainDir.Files
    Placer = InStr(1, MyFile.Name, ".") - 1
    NameSep = x - Len(MyFile.Name) + 4
    TypeSep = y - Len(MyFile.Type) + 4
    
    If Mid(MyFile.Name, InStr(1, MyFile.Name, ".") + 1) = FileExtension Then
        FileProp = Mid(MyFile.Name, 1, Placer) '& String(NameSep, "_") '& MyFile.Type & String(TypeSep, "_") & MyFile.DateCreated
        LstItems = LstItems & FileProp & ";"
    ElseIf FileExtension = "" Then
        FileProp = Mid(MyFile.Name, 1, Placer) '& String(NameSep, "_") '& MyFile.Type & String(TypeSep, "_") & MyFile.DateCreated
        LstItems = LstItems & FileProp & ";"
    End If
    
    Next
    Debug.Print LstItems
    'Clean up
    Set MyFso = Nothing
    Set MainDir = Nothing
    PopListBox = UCase(LstItems)
    
End Function

Open in new window


The user does a copy/paste to put the image files in the Explorer window but also is a file named "THUMBS".  Where is that coming from and how do I prevent it from showing up in the listbox?

--Steve
SteveL13Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MlandaTCommented:
Insert this immediately AFTER both line 16 and 25
If MyFile.Name = "THUMBS.DB" Then Continue For

Open in new window

so it will for example look like:
For Each MyFile In MainDir.Files ' all this in side this loop is to help try and format the columns a bit more uniformly.
     If MyFile.Name = "THUMBS.DB" Then Continue For

Open in new window

0
SteveL13Author Commented:
When I copy/paste that after each line you indicated I get an error...

Compile error:  Expected: Expression
0
MlandaTCommented:
You haven't by any chance broken that IF over multiple lines have you? this must be on one line, otherwise you will need to add an End IF
If MyFile.Name = "THUMBS.DB" Then Continue For
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

MlandaTCommented:
Function PopListBox(strPath As String, Optional FileExtension As String) As String

    Dim MyFso As Object
    Dim MainDir As Object
    Dim MyFile As Object
    Dim LstItems As String, FileProp As String
    Dim NameLength As Integer, InitialNameLength As Integer, TypeLength As Integer, InitialTypeLength As Integer
    Dim x As Integer, y As Integer
    Dim NameSep As Integer, TypeSep As Integer
    Dim Placer As Variant
    On Error Resume Next
    Set MyFso = CreateObject("scripting.FileSystemObject")
    Set MainDir = MyFso.GetFolder(strPath)
    InitialNameLength = 1
    InitialTypeLength = 1
    For Each MyFile In MainDir.Files ' all this in side this loop is to help try and format the columns a bit more uniformly.
        If MyFile.Name = "THUMBS.DB" Then Continue For
       NameLength = Len(MyFile.Name)
        x = IIf(NameLength > InitialNameLength, NameLength, InitialNameLength)
        InitialNameLength = x
       
        TypeLength = Len(MyFile.Type)
        y = IIf(TypeLength > InitialTypeLength, TypeLength, InitialTypeLength)
        InitialTypeLength = y
    Next
    For Each MyFile In MainDir.Files
        If MyFile.Name = "THUMBS.DB" Then Continue For
    Placer = InStr(1, MyFile.Name, ".") - 1
    NameSep = x - Len(MyFile.Name) + 4
    TypeSep = y - Len(MyFile.Type) + 4
   
    If Mid(MyFile.Name, InStr(1, MyFile.Name, ".") + 1) = FileExtension Then
        FileProp = Mid(MyFile.Name, 1, Placer) '& String(NameSep, "_") '& MyFile.Type & String(TypeSep, "_") & MyFile.DateCreated
        LstItems = LstItems & FileProp & ";"
    ElseIf FileExtension = "" Then
        FileProp = Mid(MyFile.Name, 1, Placer) '& String(NameSep, "_") '& MyFile.Type & String(TypeSep, "_") & MyFile.DateCreated
        LstItems = LstItems & FileProp & ";"
    End If
   
    Next
    Debug.Print LstItems
    'Clean up
    Set MyFso = Nothing
    Set MainDir = Nothing
    PopListBox = UCase(LstItems)
   
End Function
0
SteveL13Author Commented:
Add an endif where?
0
MlandaTCommented:
Did you try the complete method that I posted? did you still get the same error?
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
The "Thumbs.db" file is a thumbnail image cache that Windows creates and uses. It stores those little thumbnail images you see in Windows Explorer. You have no control over it, and if you delete it Windows will just remake it.

The use of "Continue" is somewhat similar to using GoTo statements, and in general I'd suggest you avoid using that sort of syntax. It tends to be difficult to understand since there's no clear indication of exactly what you're trying to do. Instead, just check for the name of that file with a standard IF - End If block.

For Each MyFile In MainDir.Files
 If MyFile.Name <> "THUMBS.DB" Then
    Placer = InStr(1, MyFile.Name, ".") - 1
    NameSep = x - Len(MyFile.Name) + 4
    TypeSep = y - Len(MyFile.Type) + 4
   
    If Mid(MyFile.Name, InStr(1, MyFile.Name, ".") + 1) = FileExtension Then
        FileProp = Mid(MyFile.Name, 1, Placer) '& String(NameSep, "_") '& MyFile.Type & String(TypeSep, "_") & MyFile.DateCreated
        LstItems = LstItems & FileProp & ";"
    ElseIf FileExtension = "" Then
        FileProp = Mid(MyFile.Name, 1, Placer) '& String(NameSep, "_") '& MyFile.Type & String(TypeSep, "_") & MyFile.DateCreated
        LstItems = LstItems & FileProp & ";"
    End If
End If
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.