PC Review


Reply
Thread Tools Rate Thread

Drive Access Error

 
 
Nigel
Guest
Posts: n/a
 
      25th Feb 2009
I have an application that tests for the existence of a text file in a
network server that has been mapped to drive Z: Depending on whether the
file exists determines the mode of the workbook. I use the following to
check.

If Len(Dir("Z:\myPath\myFile\myFile.txt")) > 0 Then
'set mode 1
Else
'set mode 2
Endif

The above works well even if the user has not got a Z: drive mapped. If the
user has a drive Z: but does not have access rights to read the folder I get
a run-time error.

How can I change the test to prevent this?

--

Regards,
Nigel
(E-Mail Removed)



 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      25th Feb 2009
I'd use:

dim teststr as string

teststr = ""
on error resume next
teststr = Dir("Z:\myPath\myFile\myFile.txt")
on error goto 0

if teststr = "" then
'nope
else
'yep
end if



Nigel wrote:
>
> I have an application that tests for the existence of a text file in a
> network server that has been mapped to drive Z: Depending on whether the
> file exists determines the mode of the workbook. I use the following to
> check.
>
> If Len(Dir("Z:\myPath\myFile\myFile.txt")) > 0 Then
> 'set mode 1
> Else
> 'set mode 2
> Endif
>
> The above works well even if the user has not got a Z: drive mapped. If the
> user has a drive Z: but does not have access rights to read the folder I get
> a run-time error.
>
> How can I change the test to prevent this?
>
> --
>
> Regards,
> Nigel
> (E-Mail Removed)


--

Dave Peterson
 
Reply With Quote
 
Nigel
Guest
Posts: n/a
 
      25th Feb 2009
Thanks Dave,

The error check fixes the permissions issue. But I am curious if testing
the Length of an empty string is different to testing for the existence of
"" ?

Cheers

--

Regards,
Nigel
(E-Mail Removed)



"Dave Peterson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'd use:
>
> dim teststr as string
>
> teststr = ""
> on error resume next
> teststr = Dir("Z:\myPath\myFile\myFile.txt")
> on error goto 0
>
> if teststr = "" then
> 'nope
> else
> 'yep
> end if
>
>
>
> Nigel wrote:
>>
>> I have an application that tests for the existence of a text file in a
>> network server that has been mapped to drive Z: Depending on whether the
>> file exists determines the mode of the workbook. I use the following to
>> check.
>>
>> If Len(Dir("Z:\myPath\myFile\myFile.txt")) > 0 Then
>> 'set mode 1
>> Else
>> 'set mode 2
>> Endif
>>
>> The above works well even if the user has not got a Z: drive mapped. If
>> the
>> user has a drive Z: but does not have access rights to read the folder I
>> get
>> a run-time error.
>>
>> How can I change the test to prevent this?
>>
>> --
>>
>> Regards,
>> Nigel
>> (E-Mail Removed)

>
> --
>
> Dave Peterson


 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      25th Feb 2009
if the dir() fails, it'll return an empty string.

I think this is more of a natural check:
if teststr = "" then

then this check:
if len(teststr)=0 then

But there wouldn't be a difference in function



Nigel wrote:
>
> Thanks Dave,
>
> The error check fixes the permissions issue. But I am curious if testing
> the Length of an empty string is different to testing for the existence of
> "" ?
>
> Cheers
>
> --
>
> Regards,
> Nigel
> (E-Mail Removed)
>
> "Dave Peterson" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > I'd use:
> >
> > dim teststr as string
> >
> > teststr = ""
> > on error resume next
> > teststr = Dir("Z:\myPath\myFile\myFile.txt")
> > on error goto 0
> >
> > if teststr = "" then
> > 'nope
> > else
> > 'yep
> > end if
> >
> >
> >
> > Nigel wrote:
> >>
> >> I have an application that tests for the existence of a text file in a
> >> network server that has been mapped to drive Z: Depending on whether the
> >> file exists determines the mode of the workbook. I use the following to
> >> check.
> >>
> >> If Len(Dir("Z:\myPath\myFile\myFile.txt")) > 0 Then
> >> 'set mode 1
> >> Else
> >> 'set mode 2
> >> Endif
> >>
> >> The above works well even if the user has not got a Z: drive mapped. If
> >> the
> >> user has a drive Z: but does not have access rights to read the folder I
> >> get
> >> a run-time error.
> >>
> >> How can I change the test to prevent this?
> >>
> >> --
> >>
> >> Regards,
> >> Nigel
> >> (E-Mail Removed)

> >
> > --
> >
> > Dave Peterson


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
error when trying to programmatically access a mapped drive =?Utf-8?B?bWF6MDE=?= Microsoft Dot NET 1 27th Jul 2006 06:03 PM
Error message when trying to access c drive danamos Windows XP Configuration 1 26th Jul 2004 04:39 AM
HARD DRIVE ACCESS ERROR LUKE Windows XP General 1 23rd Mar 2004 10:04 PM
CD drive access error? HELP! Tenex Windows XP General 2 2nd Dec 2003 10:58 PM
Access denied error after installing new hard drive Alex Windows XP Accessibility 1 30th Oct 2003 08:50 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:25 AM.