You may be getting mixed up with 2 error handling methods:
1. Use On Error Resume Next whenever you want to ignore any errors that occur and the program will continue on the line after the one that produced the error.
For example, when compacting a database called data.mdb, I normally rename the database to backup.mdb and compact using the original name. To do this, I would delete any existing backup.mdb using:
' delete existing backup.mdb if it exists
On Error Resume Next
Kill App_Path & "backup.mdb"
I use the On Error Resume Next statement to tell the program to continue if there was an error if say there was not a backup.mdb to delete.
2. Use On Error GoTo EHandler (the name of the code piece to handle the errors is up to you, so long as you have the tag defined in your code that you use on your On Error .. line) to trap errors and go to a specific piece of code.
For example, after the two lines of code above, I would then have:
On Error GoTo Err_Compact_Database
to go to this code if an error occurred while doing the compacting.
The tag Err_Compact_Database would then be placed at the end of the sub, as in:
Private Sub Compact_Database()
' delete existing backup.mdb if it exists
On Error Resume Next
Kill App_Path & "backup.mdb"
On Error GoTo Err_Compact_Database
'other code to do the compacting
Exit Sub ' this is needed so that the error handling code _
is not executed every time
Another useful way of this type of error handling is to give the user the option of retry, ignore or cancel on errors.
After the message box,
1. if the user clicks retry do Resume;
2. if the user clicks ignore do Resume Next (to continue after the line that gave the error); and
3. if the user clicks cancel do Exit Sub [sig]<p>Simon<br>[/sig]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.