Solved

Access 2010 step in macro fails

Posted on 2013-05-15
3
456 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

786 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