Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ms access vba bypassing/ignoring on error code

Posted on 2014-08-12
6
Medium Priority
?
776 Views
Last Modified: 2014-08-15
vba app in access 2k13 throws a err 7874 on a delete object docmd completely ignoring the on error procedure.

here is the code:

On Error GoTo Del_Error
DoCmd.DeleteObject acTable, "machine"  'remove source table
DoCmd.DeleteObject acTable, "repair"  'remove source table
DoCmd.DeleteObject acTable, "TrendHdr"  'remove source table
DoCmd.DeleteObject acTable, "trendmac"  'remove source table
DoCmd.DeleteObject acTable, "UPDrepair"

Call LogFileWrite("RSQueueEntryGet", "source tables deleted " & Now())
Bypass_Del:

Exit Function

Del_Error:
'MsgBox "delete error " & Err.Number & " " & Err.Description
 If Err.Number = 7874 Then   'table does not exist
        Err.Clear
        Resume Next
 End If

the error option is set to 'Break on unhandled errors'
0
Comment
Question by:jsgould
  • 2
  • 2
  • 2
6 Comments
 
LVL 85
ID: 40257978
A suggestion: In the future, when asking questions about Access VBA, you should specifically include the Access topics when posting. This question never appeared in the Microsoft Access topic area ...

When you say it's ignoring the error, do you mean it never falls to the Del_Error label, or that it does fall there, but does not execute properly afterwards?

Can you set a Breakpoint at the beginning of your code, and determine which code line it fails on?
0
 
LVL 58
ID: 40258033
Open up the VBA editor window and click on tools, options, then the general tab.

Make sure error trapping is set to "Break on Unhandled Errors".

Jim.
0
 

Author Comment

by:jsgould
ID: 40258314
Scott: it falls through the on error command and pops up the 7874 error on the first docmd.if I set next statement to each of the following docmds I get the same error

Jim: note in the issue description that I state that break on unhandled errors is set
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 1000 total points
ID: 40258380
I would simply do this:

' Delete the tables if they exist.  Ignore any warnings if they don't.
On Error Resume next
DoCmd.DeleteObject acTable, "machine"  'remove source table
DoCmd.DeleteObject acTable, "repair"  'remove source table
DoCmd.DeleteObject acTable, "TrendHdr"  'remove source table
DoCmd.DeleteObject acTable, "trendmac"  'remove source table
DoCmd.DeleteObject acTable, "UPDrepair"
On Error Goto Del_Error
0
 
LVL 85

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 1000 total points
ID: 40258482
Agreed with Jim - there's no reason to even involve error handling if you're going to ignore it.

FWIW - you could check to be sure the object exists before you remove it, but that's something of a waste of time (since your only action after checking is to remove it).

You could also use straight SQL to do this:

Currentdb.Execute "DROP TABLE machine"
Currentdb.Execute "DROP TABLE repair"
etc etc
0
 

Author Closing Comment

by:jsgould
ID: 40263994
Thanks folks for fast, effective response even though I posted to the wrong place
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question