Verify path of file but not open it

C

chuck

Hi,

I have a form with a subform. The record source for the subform contains
consists of paths to external files. I'm using the apiShellExecute function
(http://www.mvps.org/access/api/api0018.htm) to open a specific file when
the control is double-clicked. All is good.

Now, I would want to able to loop through the subform's recordset and verify
if the paths are acutually valid without actually opening the file. I can
loop through the recordset just fine but I'm not sure how to only verify the
file path.

Can I do this with apiShellExecute ? None of the parameters passed to the
function appear to let me simply return an error if the file path is invalid
and NOT open the file if the path is valid.

Does another function exist that will let me do this ?

Thanks
 
D

Douglas J. Steele

Assuming these aren't http URLs, you can use the Dir function to determine
whether the file exists.

If Len(Dir(strFullPath)) > 0 Then
' The file exists
Else
' The file does not exist
End If
 
M

Marshall Barton

chuck said:
I have a form with a subform. The record source for the subform contains
consists of paths to external files. I'm using the apiShellExecute function
(http://www.mvps.org/access/api/api0018.htm) to open a specific file when
the control is double-clicked. All is good.

Now, I would want to able to loop through the subform's recordset and verify
if the paths are acutually valid without actually opening the file. I can
loop through the recordset just fine but I'm not sure how to only verify the
file path.

Can I do this with apiShellExecute ? None of the parameters passed to the
function appear to let me simply return an error if the file path is invalid
and NOT open the file if the path is valid.

Does another function exist that will let me do this ?


The Dir function might be sufficient. It returns an empty
string if the path does not exist.
 
C

chuck

thanks. Works great.


Douglas J. Steele said:
Assuming these aren't http URLs, you can use the Dir function to determine
whether the file exists.

If Len(Dir(strFullPath)) > 0 Then
' The file exists
Else
' The file does not exist
End If
 
G

Guest

Chuck,

I actually have a function fnValidPath( ) that I use, which I can put in the
query as a computed field. That way, I can use that value in a conditional
formatting of the file name to indicate whether the path is valid (blue) or
invalid (black). I Also use the value of that field to enable/disable the
button that opens the file when a specific record is selected.

Public Function fnValidPath(FileName as string) as boolean

fnValidPath = LEN(DIR(FileName)) > 0

End Function

HTH
Dale
 
G

Guest

Doug,

I like Randy's API call (I use them frequently, but had not seen one for
this purpose before).

Can you give me an indication why the fnValidPath function would "cause
problems"?

Dale
 
D

Douglas J. Steele

If you've got a loop that uses the Dir function, like:

Dim strFolder As String
Dim strFile As String

strFolder = "F:\Some Folder\Some Other Folder\"
strFile = Dir(strFolder & "*.txt")
Do Until Len(strFile) = 0
' Code that does something here
strFile = Dir()
Loop

and you somehow call your fnValidPath function while that loop is running,
you'd reset the context of the Dir function.

It's easy to forget, and have a sub call a sub call a sub that calls
fnValidPath (I know I've done it before)
 
C

chuck

I might have to try the other solutions provided. DIR() works fine if the
filename or the directories are wrong. however if the root of path is wrong
(I use UNC path like \\myserver.mydomain.com\share), then DIR() just returns
an run-time error.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top