Solved

Can't recoginze file extension

Posted on 2002-06-28
9
317 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 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
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 …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

617 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