Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Access 2010 step in macro fails

Posted on 2013-05-15
3
Medium Priority
?
462 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 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
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…
Suggested Courses

971 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