Custom runtime error messages

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?

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

Select Case Err.Number
Case 70
'-- Error 70 - permission denied
MsgBox Err.Description
End Select
End Function

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 ...

'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
End Select

End SubEnd Sub

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.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum