supress an error

O

Odbodypierre

Hi I need to stop any error messages coming up on the
screen is there a way i can supress all the errors and
just create an entry in a table of the error number and
the time & date

I cant seem to find anything as simple as this out there

any ideas?

Thanks

Odbodypierre
 
R

Ron Kunce

You should NOT have a general policy to log all errors then move on as if
there were no error. You need to also have a errorhandler table to specify
the action to be taken for each error. I would suggest both error log AND
an error handler table, to use code like the following example in every
routine with more than one line of code:

Function GetScreenResolution() As String
'***************************************************************************
**********************
' FUNCTION: GetScreenResolution()
' PURPOSE: To determine the current screen size or resolution.
' RETURNS: The current screen resolution.
' Typically one of the following: '640x480', '800x600',
or '1024x768'.
'***************************************************************************
**********************

Dim R As RECT
Dim hWnd As Long
Dim RetVal As Long

On Error GoTo FAILURE

hWnd = GetDesktopWindow()
RetVal = GetWindowRect(hWnd, R)
GetScreenResolution = (R.x2 - R.x1) & "x" & (R.y2 - R.y1)

ExitRoutine:
Exit Function

' Error handling block added by Error Handler Add-In. DO NOT EDIT this block
of code.
' Automatic error handler last updated at 09-26-2001 11:29:16
'ErrorHandler:$$D=09-26-2001 'ErrorHandler:$$T=11:29:16
FAILURE:
apCurrErrNo = Err.Number
apCurrErrMsg = Err.Description
apCurrErrLin = Erl()

ap_ErrorLog "basUtilities", "GetScreenResolution", apCurrErrNo,
apCurrErrMsg 'ErrorHandler:$$N=basUtilities.GetScreenResolution
Select Case ap_ErrorHandler(apCurrErrNo, apCurrErrMsg)
Case apTryAgain
Resume
Case apExitRoutine
Resume ExitRoutine
Case apResumeNext
Resume Next
Case Else
MsgBox "Error " & apCurrErrNo & ": " & apCurrErrMsg, vbCritical,
"basUtilities.GetScreenResolution"
'ErrorHandler:$$N=basUtilities.GetScreenResolution
Resume ExitRoutine
End Select
' End Error handling block.
End Function

The "On Error GoTo FAILURE" line will break out of the body of your code
whenever an error occurs and begin executing the code in the FAILURE: block
which uses the Select Case statement to evaluate the returning code from an
errorhandler function to determine if the faulty line should be tried again
(Resume), quit the Routine (Resume ExitRoutine - which jumps the code back
to the ExitRoutine label and quits), or skip the current (error causing)
line and begin on the next line (Resume Next) and with a default if the
actual error has no handling block in the errorhandler table.


2005 >>>
Hi I need to stop any error messages coming up on the
screen is there a way i can supress all the errors and
just create an entry in a table of the error number and
the time & date

I cant seem to find anything as simple as this out there

any ideas?

Thanks

Odbodypierre
 
O

Odbodypierre

I am not that good with vba should I add that to a module
or in a form level script?

Thanks

Odbodypierre
-----Original Message-----
You should NOT have a general policy to log all errors then move on as if
there were no error. You need to also have a errorhandler table to specify
the action to be taken for each error. I would suggest both error log AND
an error handler table, to use code like the following example in every
routine with more than one line of code:

Function GetScreenResolution() As String
'******************************************************** *******************
**********************
' FUNCTION: GetScreenResolution()
' PURPOSE: To determine the current screen size or resolution.
' RETURNS: The current screen resolution.
' Typically one of the
following: '640x480', '800x600',
 
R

Ron Kunce

Too bad! using an errorhandler takes some rudimentary VBA knowledge. I was
trying to find an example .mdb file with some basic error handling code, but
all my stuff has been highly modified. Lets try something simpler with no
logging and no automatic error handling. Use this example in all your
routines:

Sub Example()
'Put your variable declaration here!

On Error GoTo HandleErr

'Put your code here!

ExitHere:
Exit Sub

HandleErr:
Select Case Err.Number
Case 2501
Resume Next
Case 2502
Resume
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical,
"Form_frmDialog.test"
Resume ExitHere
End Select
End Sub


In the select case we are grabbing specific error numbers (i.e., 2501) and
telling the code to Resume Next with the next line (following the line with
the error) of code in the body. Or, for other error numbers (i.e., 2502) we
are saying try the line with the error again (only for errors which you know
are repeatable which will most likely will be none). The Case Else prints
the error showing the form name and routine name in the msgbox title then
goes to the ExitHere block. You could use a "Resume ExitHere" without a
msgbox to quit the routine without displaying the error message, but then
you wouldn't know why the routine aborted in mid-step. The "Resume Next" is
valuable for errors like 2501, "The RunCommand action was canceled." where
the cancel was a user response and error message need not be displayed and
you want to continue with the next line of code.

You can add a logging routines and errorhandling routines when you have
become more familiar with VBA coding. I would suggest a good book on Access
programming, before you buy one, check the index for error handling
chapters.


2005 >>>
I am not that good with vba should I add that to a module
or in a form level script?

Thanks

Odbodypierre
-----Original Message-----
You should NOT have a general policy to log all errors then move on as if
there were no error. You need to also have a errorhandler table to specify
the action to be taken for each error. I would suggest both error log AND
an error handler table, to use code like the following example in every
routine with more than one line of code:

Function GetScreenResolution() As String
'******************************************************** *******************
**********************
' FUNCTION: GetScreenResolution()
' PURPOSE: To determine the current screen size or resolution.
' RETURNS: The current screen resolution.
' Typically one of the
following: '640x480', '800x600',
 

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