Solved

Access 2010 step in macro fails

Posted on 2013-05-15
3
451 Views
Last Modified: 2013-05-16
I have a macro in Access 2010 with several queries. One query has a ODBC connection. when the connection fails for any reason, I want to do something else. Is there a way to detect a failure of a specific query in a macro and do something if it fails or would I have to create a stand alone macro and see if the macro itself fails?

Thanks
0
Comment
Question by:LeLeBrown
  • 2
3 Comments
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 500 total points
ID: 39170414
Does this absolutely need to be done in a macro (is this a web database?)

This is easy to do in VBA.

You can trap the ODBC error in your error handler:

Sub RunQueries()

On Error GoTo Err_RunQueries

********** Your Code Goes Here **********

Exit_RunQueries:
    Exit Sub

Err_RunQueries:
    'If ODBC error
    If Err.Number = 3146 Then
        'Do Something...?
        Resume Exit_RunQueries
    Else
        MsgBox "There was an error executing the command." _
        & vbCrLf & "Error " & Err.Number & ": " _
        & vbCrLf & Error, vbExclamation
        Resume Exit_RunQueries
    End If

End Sub


But you need to be more specific on what your mysterious "Do something" means...
..as this might not be what you want.

JeffCoachman
0
 

Author Comment

by:LeLeBrown
ID: 39171282
Hi Jeff,

Thanks for the response. I ended up doing something in VBA like your example.
To explain further:
I have one query that depends on a ODBC connection that creates a Access local table. If the connection is not available (which seems to happen with some frequency), I don't want my code to stop(because it runs on its own - set up as a task in task manager). I created a macro to run this query and called it from VBA. If it fails (I don't care why), I run another macro that makes a table based on the old data copied from the previous day(that doesn't rely on the odbc conn).
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 39171340
OK, so if my post helped you in some way, then I am happy
;-)
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now