Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Can't recoginze file extension

Posted on 2002-06-28
9
Medium Priority
?
327 Views
Last Modified: 2012-08-13
This code is supposed to decide if an image is .jpg or .bmp. "MatchTextExactly = True" always comes back false even if the file is there.

What am I doing wrong?


Function setImagePath()
Dim number
Dim strImagepath As String

strImagepath = Forms!frmSmokeTest!txtPath & Me.strImage 'strImage is a name without an extension

With Application.FileSearch

.NewSearch
  .LookIn = Forms!frmSmokeTest!strPhotoStored
.SearchSubFolders = True
   .FileName = Me.strImage & ".bmp"
   If .MatchTextExactly = True Then
   strImagepath = strImagepath & ".bmp"

    Else
    .NewSearch
  .LookIn = Forms!frmSmokeTest!strPhotoStored
.SearchSubFolders = True
   .FileName = Me.strImage & ".jpg"
   If .MatchTextExactly = True Then
   strImagepath = strImagepath & ".jpg"
End If
End If

  .FileType = msoFileTypeAllFiles
End With

Thanks,
Kate
0
Comment
Question by:pipelinevideo
9 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 7116801
Hi pipelinevideo,

it looks correct so have you checked what is in the strImagepath variable?

you can add this line to see if the string is correctly with all the \ slashes etc...and of course the exact string caps or all small letters
if you change the matchexactly to false is it picking up the correct files then?

strImagepath = Forms!frmSmokeTest!txtPath & Me.strImage
msgbox strImagepath

HAGD:O)Bruintje
0
 
LVL 4

Accepted Solution

by:
Nevaar earned 400 total points
ID: 7116923
Aren't you missing an .Execute statement before the .MatchTextExactly test?
0
 

Author Comment

by:pipelinevideo
ID: 7117454

I'm not sure that .Execute is relevant here (although I did try it out, just in case, isn't it more related to record sets?)

The msgbox was a good idea. I realized that SetImagePath cycles twice. The first time it returns the correct path (including \ etc) the second time it returns the samething minus the file name. As long as I'm dealing with only one file extension, it doesn't seem to hurt the report.

Is it SetImagePath's nature to cycle?

Yes, if I change True to False it works perfectly as long as I've removed all refences to the .jpg files on the form.

Thanks,
Kate

0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 44

Expert Comment

by:bruintje
ID: 7117500
Dear Kate

what is this code supposed to do?

a function always returns a value
if not then you better use a sub
proper indenting could help in readabillity

Function setImagePath() as string
Dim strImagepath As String

  strImagepath = Forms!frmSmokeTest!txtPath & Me.strImage 'strImage is a name without an extension
  With Application.FileSearch
    .NewSearch
    .LookIn = Forms!frmSmokeTest!strPhotoStored
    .SearchSubFolders = True
    .Filename = Me.strImage & ".bmp"
    msgbox .Filename ' just a check
    If .MatchTextExactly = True Then
      strImagepath = strImagepath & ".bmp"
    Else
      .NewSearch
      .LookIn = Forms!frmSmokeTest!strPhotoStored
      .SearchSubFolders = True
      .Filename = Me.strImage & ".jpg"
      msgbox .Filename ' just a check
      If .MatchTextExactly = True Then
        strImagepath = strImagepath & ".jpg"
      End If
    End If
    .FileType = msoFileTypeAllFiles
  End With
  ' this returns the file + path name
  setImagePath = strImagepath
End Function

you say it goes twice through this function then it is called twice in a row in the same part of the rest of the code

Brian
0
 

Author Comment

by:pipelinevideo
ID: 7117590
Apologizes for the sloppy indents.

As I said in the first message this code is supposed to decide if an image in a directory is .jpg or .bmp then send the image to a report.

I noticed something interesting, .MatchTextExactly does not play well with if-then. As soon as I used .MatchTextExactly by itself, it recognized if it was True or False.

I'll work on this a bit more and get back.

Thanks,
Kate
0
 
LVL 7

Expert Comment

by:ildc
ID: 7118405
Hi Kate,

Little code enhancment. Instead of :

if matchtextexactly = true then ...

just put :

if matchtextexactly then ...


since it's always returning true or false


regards
0
 

Author Comment

by:pipelinevideo
ID: 7118771
Hi,
The first way it always returns a false, whether or not the file is a bmp or even exists and the second way always returns a true. There has to be some principle that I'm missing. HELP.

The reason I'm not using the extension in the form is that it is the same name for clips and still images. The user can click the line and see a still or clip, depending on which form they are in.

Thanks,
Kate

______________________________________________________
FIRST WAY

strImagepath = Forms!frmSmokeTest!txtPath & Me.strImage

With Application.FileSearch
   .NewSearch
   .LookIn = Forms!frmSmokeTest!strPhotoStored
   .SearchSubFolders = True
   .FileName = Me.strImage & ".bmp"
        If .MatchTextExactly Then
           strImagepath = Application.FileSearch.FileName
        End If
   .FileType = msoFileTypeAllFiles
End With

____________________________________________
SECOND WAY


strImagepath = Forms!frmSmokeTest!txtPath & Me.strImage

With Application.FileSearch
   .NewSearch
   .LookIn = Forms!frmSmokeTest!strPhotoStored
   .SearchSubFolders = True
   .FileName = Me.strImage & ".bmp"
   .MatchTextExactly = True
   .FileType = msoFileTypeAllFiles
End With

If Application.FileSearch.MatchTextExactly Then
  strImagepath = Application.FileSearch.FileName
  Exit Function
End If
0
 

Author Comment

by:pipelinevideo
ID: 7118877
Kudos to everyone that responded! I accepted Nevaar's answer because even though it didn't work as advertised, it got me thinking about .execute

I'd like to give 100 points to everyone that answered, without all of your input I wouldn't have come up with the answer.

Please give 100 points to:
bruintje
nevaar
ildc

Is this the right way to do this or do I have to send a request to someone?

Here's what works, it may not be pretty but it gets the job done.

Thanks,
Kate

____________________________________________

Function setImagePath()

On Error Resume Next
Dim strImagepath As String
Dim number
Dim intFilesFound As Integer

number = Me.strPhotoLocation
number = IsNull(number)
If number = True Then
 strImagepath = Forms!frmSmokeTest!txtPath & "NoPhoto.jpg"
 Exit Function
End If

strImagepath = Forms!frmSmokeTest!txtPath & Me.strImage

With Application.FileSearch
   .NewSearch
   .LookIn = Forms!frmSmokeTest!strPhotoStored
   .SearchSubFolders = True
   .FileName = Me.strImage & ".bmp"
   .MatchTextExactly = True

    intFilesFound = .Execute
        If intFilesFound > 0 Then
            strImagepath = .FileName
            Exit Function
        Else
   .NewSearch
   .LookIn = Forms!frmSmokeTest!strPhotoStored
   .SearchSubFolders = True
   .FileName = Me.strImage & ".jpg"
   .MatchTextExactly = True
    intFilesFound = .Execute
        If intFilesFound > 0 Then
          strImagepath = .FileName
       End If
       End If
End With

End Function
0
 
LVL 44

Expert Comment

by:bruintje
ID: 7118883
glad you got a working solution

if you want to reward other participants then you can ask seperate questions in this access forum with the title

points for <name of the participant>

Brian
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question