Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Handling Prob

Status
Not open for further replies.

TidyTrax

Programmer
Jul 11, 2001
263
AU
I have a access application that creates a series of dynamic tables, the problem i am having is when i try to create a table that has already been created, i error handle this by deleting the old table and then recreating it. This is incase the data has changed. I do so like so:

Case 3010
If (tablesList.Value = "tblPetitions" And tablesInList.Value = "Petitions Percentage Calc" And AreaTotalCombo.Value = "Area Totals") Then
DoCmd.DeleteObject acTable, OfficeCombo.Value & " Petitions % from " & qDateBegin & " to " & qDateEnd2
MsgBox "Old Table Deleted"
GoTo pet_start_point
End If
If (tablesList.Value = "tblPetitions" And tablesInList.Value = "Petitions Percentage Calc" And AreaTotalCombo.Value = "Show Offices" And OfficeCombo.Value = "Highlands and Islands") Then
DoCmd.DeleteObject acTable, "HLands & Islands Pets Office % from " & qDateBegin & " to " & qDateEnd2
MsgBox "Old Table Deleted"
GoTo pet_start_point
Else
If (tablesList.Value = "tblPetitions" And tablesInList.Value = "Petitions Percentage Calc" And AreaTotalCombo.Value = "Show Offices") Then
DoCmd.DeleteObject acTable, OfficeCombo.Value & " Pets Office % from " & qDateBegin & " to " & qDateEnd2
MsgBox "Old Table Deleted"
GoTo pet_start_point
End If
End If
-----------------------------------------------------------

Now the problem is now, when it goes back to the pet_start_point, the other error handlers are ignored. FOr example, so of the calculations could be handed a zero to divide by, the error handler should just by pass this. But once it seems to handle the Table Already Exists error, the rest of the error handlers dont seem to work.

Anyone know why?
 
By using GoTo that way, you are effectively remaining in error handling mode. VBA doesn't report errors when it is handling an error.

Executing things like DoCmd while in an error handler is dangerous for just that reason. Any errors that occur while trying to do the command won't get reported.

Study the error topics in the help file for the proper way to handle errors.

Most of the time, you don't need a separate error handler. Usually you can do is something like this:
Code:
   On Error Resume Next
   DoCmd.DeleteObject
   On Error Goto 0
   ' Continue processing. 
   ' If the object existed, it is deleted.
   ' If an error occurred we will be here anyway.
The only problem is that the command could fail for some other reason and the object did in fact exist and still does. In that case you will get a new error when trying to do the create. So you could handle that at that time, or make this bit of code more complicated just to handle the .01% case. The choice is yours.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top