Solved

Access 2010 step in macro fails

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

911 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

18 Experts available now in Live!

Get 1:1 Help Now