Solved

Can't recoginze file extension

Posted on 2002-06-28
9
269 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
 
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Access 2010 3 19
Code not working properly when in macro module 18 36
add more styles to my code 2 19
Help with SQl and UNION 7 16
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server views 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 Microsoft Access…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now