Trouble with null files

Geezer

Registered User.
Local time
Today, 11:59
Joined
Jul 14, 2008
Messages
62
Hi,

Posted a short thread the other day with regards picking up an error message if the file length was null. I've managed to get halfway there but am still having some issues and was hoping someone could help. Here's the code I'm runing off a button in a form:

Private Sub ViewLogImage_Click()

Dim WellPath
WellPath = Dir("W:\Open\" & "*" & Me.Name.Value & "*", vbDirectory)

Dim ProjPath
ProjPath = "W:\Open\" & WellPath & "\" & Name & ".TIF"

If Len(WellPath) = 0 Then
MsgBox "No Image Available for " & Me.Name.Value
Else
Shell "C:\Program Files\Mozilla Firefox\firefox.exe """ & ProjPath & "", vbNormalFocus

End If

End Sub


All is fine except that ideally I'd like the MsgBox to pop up if the ProjPath is null. When I substitute the If Len(WellPath) with If Len(ProjPath) the If Else doesn't work. At the moment it's only working if the folder (WellPath) doesn't exist. However if the folder exists and the file doesn't Firefox opens with a file not foud error. Obviously I'd like to skip this and let the user know the file doesn't exist without Firefox opening with an error.

Any ideas would really be appreciated, I'm slowly going insane :mad:. Does Len only work with Dir?

Thanks

Gareth
 
You really need to rename whatever it is that is named NAME. That is an Access reserved word and Me.Name refers to the name of the current class object (form or report). Do that to start with and you might have more luck.
 
Oops - Correction

Was trying to make things a little simpler, which may just have confussed things. "Name" is actually "WellName" which makes Me.Name.Value actually Me.WellName.Value, if that makes sense.

Sorry for any confussion.
 
Len() gives the length of the data in the variable you pass to it. In your case, the length of ProjPath is going to be at least 12, since that is how many constant characters you are giving to it. Since it will always be 12 or greater, it will never be 0, thus the Else clause will always be invoked (assuming the rest of the code other than the name of one of your variables is an accurate representation of what is happening).
 
Len() gives the length of the data in the variable you pass to it. In your case, the length of ProjPath is going to be at least 12, since that is how many constant characters you are giving to it. Since it will always be 12 or greater, it will never be 0, thus the Else clause will always be invoked (assuming the rest of the code other than the name of one of your variables is an accurate representation of what is happening).

How true - The correct function to find out if it exists would be

If Dir(ProjPath) <> "" Then
 
Last edited:
Thanks Fellas

All starting to make sense. I'll give If Dir(ProjPath) <> "" Then a go when I get back to work next week and let you know if iw works. The rest of the code is accurate btw.

I'm assuming I could also use:

If Len(Dir(ProjPath))=0 Then

??

Thanks heaps, much appreciated.
 
Re: Thanks Fellas

If Len(Dir(ProjPath))=0 Then
That would be uneccessary.

If Dir(ProjPath) <> ""

is sufficient as it will be "" if the path doesn't exist and it will not equal "" if the path does exist.
 
Odd!

Interestingly enough

If Len(Dir(ProjPath))=0 Then

seems to work fine, file not found message pops up no problem

With

If Dir(ProjPath) <> ""

I still get nothing happening when I press the button in the case where the folder exists but the file doesn't.

Thanks again to both you guys for lending a hand, much appreciated.
 
If Dir(ProjPath) <> ""

is not the same as

If Len(Dir(ProjPath))=0 Then


It is actually reversed. So, if you wanted them to act the same so that the same thing could be put in the same place then you would need:

If Dir(ProjPath) = "" Then
 
Yip!

Makes sense,

If Dir(ProjPath) = "" Then

works great, same as the Len option.
 

Users who are viewing this thread

Back
Top Bottom