Over riding a run time error

  • Thread starter chris0309 via AccessMonster.com
  • Start date
C

chris0309 via AccessMonster.com

Is it possible to overwrite a specific run time error message with my own
message box?

Thats for any help.

Chris
 
D

Danny J. Lesandrini

I've never used this before, but there is a Raise method of the Err object.

Const MyContextID = 1010407 ' Define a constant for contextID.
Function TestName(CurrentName, NewName)
If Instr(NewName, "bob") Then ' Test the validity of NewName.
' Raise the exception
Err.Raise vbObjectError + 513, "MyProj.MyObject", _
"No ""bob"" allowed in your name", "c:\MyProj\MyHelp.Hlp", _
MyContextID
End If
End Function
 
D

Danny J. Lesandrini

Ooops, I forgot the obvious. Just test for the error number and present a message box
with your error for that case. Other cases you can display the Err.Description.

When you hear hoofbeats, think horses not zebras.
 
D

DStegon via AccessMonster.com

Of course. You have to trap the error and then write either a select case or
if statement to have it say what you want it to say. The best way is to
write error handling code that goes to a specific area for handling.

Private Function WhatEver() as something
On Error GoTo HandleErr

code snip... blah
if
yada
blah
end if

exithere:
Exit Function

HandleErr:
If QueueError(Err) Then GoTo exithere
Resume

End Function

Public Function QueueError(ByVal Errobj As ErrObject)
Static InQError As Boolean
If Errobj.Number = 0 Then Exit Function
If InQError Then
Exit Function
End If

Dim whodunnit As String
Dim msg As String
Dim objProc As Procedure
Dim strProcList As String
Dim strSize As String
Dim strFree As String
Dim intPercent As Integer
Dim strPath As String
Dim mst As adhMEMORYSTATUS
Dim strDiskInfo As String
Dim i As Integer
Dim atypFreeDiskSpace() As adhFreeDiskSpaceType
Dim cat As New ADOX.Catalog
Dim tbl As ADOX.Table
Dim rst As New ADODB.Recordset
Dim ErrorDescription As String
Dim TopProcedure As String
Dim strCodePoint As String
Dim UsingEmail As Boolean
Dim rstE As New ADODB.Recordset
Dim rstED As New ADODB.Recordset
Dim strcnn As String
Dim error_number As String
Dim error_description As String
Dim error_helpfile As String
Dim error_helpcontext As String
Dim error_source As String
Dim error_lastdllerror As String
Dim Error_Log As String

error_number = CStr(Errobj.Number)
error_description = CStr(Errobj.Description)
error_helpfile = CStr(Errobj.HelpFile)
error_helpcontext = CStr(Errobj.HelpContext)
error_source = CStr(Errobj.source)
error_lastdllerror = CStr(Errobj.LastDllError)
ErrorDescription = Errobj.Description

msg = msg & "Error Description: " & ErrorDescription & vbCrLf & vbCrLf
msg = msg & "Procedure: " & TopProcedure & vbCrLf & vbCrLf
msg = msg & "Executing: " & strCodePoint & vbCrLf & vbCrLf

' If error_number <> -2147467259 Then ' This is a record-Locking update
error
' msg = msg & "Error Number: " & Left(error_number, 255) & vbCrLf &
vbCrLf
' msg = msg & "Error Desc: " & Left(error_description, 255) & vbCrLf &
vbCrLf
' msg = msg & "Error HelpFile: " & Left(error_helpfile, 255) & vbCrLf
& vbCrLf
' msg = msg & "Error Help Context: " & Left(error_helpcontext, 255) &
vbCrLf & vbCrLf
' msg = msg & "Error Source:" & Left(error_source, 255) & vbCrLf &
vbCrLf
' msg = msg & "Error Last Error: " & Left(error_lastdllerror, 255) &
vbCrLf & vbCrLf
' End If

exithere:
InQError = False

End Function


You can adjust the code as necessary to test for whatever error you are
trying to catch and have it then send a msg to the screen with the MsgBox
command.
 
D

DStegon via AccessMonster.com

I took out a bunch of code that we use because we save all the errors and
match the error code against data that is then matched and the program then
sends an email to the programmer responsible for the area of the code that
the error came from so you will see variable in the "DIMs" that are not used
in the edited section I gave. Sorry for any confusion.
 

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