Solved

Can't recoginze file extension

Posted on 2002-06-28
9
298 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 100 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
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.

789 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