Checkbox to let user know if photos exist in a folder

SteveL

Registered User.
Local time
Today, 11:01
Joined
Dec 3, 2004
Messages
60
I am trying to make a checkbox on a form check (be true) if a certain folder on the C drive of the user's computer exists and if any jpg files are in that folder. The following is my code of the on current event of the form. But it is not checking the checkbox when jpg files do exists in the folder. What have I done wrong?

If Len(Dir("C:\Company\General Shared Files\PRINTS\" & Me.txtPartN & "\*.jpg")) = 0 Then
Me.chkprints = False
Else
Me.chkprints = True
End If

--Steve
 
Maybe because the output is like:

Code:
C:\Company\General Shared Files\PRINTS\" & Me.txtPartN & "\[color=red]*[/color].jpg

Unless you have any file named Part1*.jpg, it won't check as true. If you remove the * it should work, especially if your Me.txtPartN is the actual name of the file, so there's no need for any wildcard characters.
 
Actually, the --- " & Me.txtPartN & " --- part of the code is the folder name. Then within the folder the --- *.jpg --- part indicates the files in the folder. So I do need the *, correct? (I did try to remove it and it still didn't work.
 
Apparently I didn't have enough caffeine in me when I first read that, not catching that second slash before the wildcard.

Anyway- I suspect this is a case where we can't use wildcards because VBA thinks you want to look for a file actually named '*.jpg' and returns false. I would google a bit more on doing wildcards in VBA to check if this is indeed the case or if there can be workaround.

It's usually simpler to be able to refer to the actual name, rather using a wildcards, or at least find out if you can retrieve counts of file within a directory instead using APIs, I'd think.
 

Users who are viewing this thread

Back
Top Bottom