realphx
08-09-2005, 07:58 AM
In my program, it creates files in a directory that some accounts wont allow new files to be added. If its run on a guest account, it says runtime error 70, permission denied. How can i make it so it says my custom error message "You dont have admin rights to run this program" instead of VB's runtime error?
wakjah
08-09-2005, 08:08 AM
You need to handle the error in the method where it occurs first - like this:
Public Function Foo() As Boolean
On Error GoTo ProcErr
'-- Do Something
'-- Make sure we don't run the error handling stuff if there's no need
Exit Function
ProcErr:
Select Case Err.Number
Case 70
'-- Error 70 - permission denied
MsgBox Err.Description
End Select
End Function
Diurnal
08-09-2005, 08:14 AM
Use some error handling code and trap the error. You can then display a message box with any text that you need:
Some Sub()
'turn on error handling:
On Error GoTo SomeSubError
'Blah Blah Blah ...
SomeSubError:
'If here, an error has occured.
Select Case Err.Number
Case Is = 70
MsgBox "You dont have admin rights to run this program."
Case Else
Debug.Print Err.Number, Err.Description
Debug.Print
End Select
End SubEnd Sub
realphx
08-09-2005, 08:26 AM
Thanks, both systems work perfectly. I created a small program that keeps the windows clock frozen at a certian time. It creates a bach file in the windows directory to execute and on some limited accounts it will display that error message instead.