Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Can't recoginze file extension

Posted on 2002-06-28
9
Medium Priority
?
322 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

688 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