Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

run-time error '70' 1

Status
Not open for further replies.

mscallisto

Technical User
Jun 14, 2001
2,990
US
I'm running some excel vb code to search for .pst files on my c:\ drive on a win2k box.

I get [run-time error '70' permission denied] message box that doesn't tell me too much.

Where can I place something like an "IF(ISERROR(" statement where I can gain control with my own msgbox?

I know the problem is "permissions" related.
My login has admin rights and windows explorer search has no permissions problems.

My real problem is error control in vba, I want to be in command when all errors occur. Can I do this?

Thanks in advance

 
mscallisto,

Sure. Set up your procedure something like:

Code:
Sub MyProcedure

  On Error GoTo MyProcedure_Error

' Your existing code here

MyProcedure_Exit:
' Optional cleanup code here (Note: normal sub exit will
' also run this. If specific to error condition then
' place in error handler section)
  Exit Sub

MyProcedure_Error:
  If Err.Number = 70 Then
    'Special handling for error 70
    Resume Next
  Else
    'Message to user here for other errors, perhaps
    Resume MyProcedure_Exit 'Run cleanup then exit sub
  End If

End Sub

The labels
Code:
MyProcedure_Error
and
Code:
MyProcedure_Exit
can be whatever you want. The
Code:
Resume Next
will return control to the statement immediately following the one causing the error. This may or may not be appropriate. Another way to handle this would be to place a
Code:
On Error Resume Next
statement just prior to the section of code likely to generate a specific error then explicitly test for this on the next line. Example:

Code:
On Error Resume Next
  ' Code that may trigger an error here
  If Err.Number <> 70 Then
  ' Code that should run only if no error 70
  Else
  'Optional - Could be message to user or other action taken
  End if

There are other variations, as well.

HTH
Mike
 
Thanks Mike

Thats exactly what I wanted!!!
 
Oh and I failed to give a star where one was certainly due.

You should post this as a helpful tip or FAQ

thanks again
mscallisto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top