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