Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / March 2005

Tip: Looking for answers? Try searching our database.

supress an error

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Odbodypierre - 30 Mar 2005 20:07 GMT
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
Ron Kunce - 30 Mar 2005 21:00 GMT
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.

>>> Odbodypierre<anonymous@discussions.microsoft.com> Wednesday, March 30,
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
Odbodypierre - 30 Mar 2005 21:09 GMT
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
[quoted text clipped - 79 lines]
>
>.
Ron Kunce - 30 Mar 2005 23:41 GMT
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.

>>> Odbodypierre<anonymous@discussions.microsoft.com> Wednesday, March 30,
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',
>or '1024x768'.
>'********************************************************
*******************
>**********************
>  
[quoted text clipped - 7 lines]
>   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:
[quoted text clipped - 3 lines]
>  
>   ap_ErrorLog "basUtilities", "GetScreenResolution",
apCurrErrNo,
>apCurrErrMsg  'ErrorHandler:$$N=basUtilities.GetScreenRes
olution
>   Select Case ap_ErrorHandler(apCurrErrNo, apCurrErrMsg)
>      Case apTryAgain
[quoted text clipped - 5 lines]
>      Case Else
>         MsgBox "Error " & apCurrErrNo & ":  " &
apCurrErrMsg, vbCritical,
>"basUtilities.GetScreenResolution"
>'ErrorHandler:$$N=basUtilities.GetScreenResolution
[quoted text clipped - 4 lines]
>
>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.

>>>> Odbodypierre<anonymous@discussions.microsoft.com>
Wednesday, March 30,
>2005 >>>
>Hi I need to stop any error messages coming up on the
[quoted text clipped - 11 lines]
>
>.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.