?
Solved

How to determine if a query has executed successfully?

Posted on 2003-12-08
5
Medium Priority
?
686 Views
Last Modified: 2011-08-18
I have a macro that runs three action queries one after the other (OpenQuery). I want to execute the 2nd and 3rd query only if the first action query (update) was executed successfully (No violations etc...). How can I do it? As of now, Access continues to execute the remaining queries no matter whether the first query was successfully executed or not. How can I check whether the first query was successfully executed?
Thanks
0
Comment
Question by:Sankar030999
  • 2
  • 2
5 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 9897324
what code are you currently using to do this?

AW
0
 

Author Comment

by:Sankar030999
ID: 9897339
I am not using any code. I am just doing it from within Access. I created the queries within Access and create a Macro in Access to run all the queries (OpenQuery) one after the other.
Sankar
0
 
LVL 32

Accepted Solution

by:
jadedata earned 2000 total points
ID: 9897356
Hey Sankar!

  If you switch to using VBA code to perform this:
 
  You can use the command
  db.execute "QueryName", dbfailonerror

  1.  If a query fails, a trappable error is raised.
  2.  If you want to know if RECORD were affected by the query (like how many updates were performed)
     you can ask Access for

   x = db.recordsaffected
   if x > 0 then
     'do this
   else
     'stop here
   endif

See Access help for examples of the execute method and recordsaffected properties

These are DAO object children that require the inclusion of the MS DAO 3.6 object library.
regards
Jack
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 9897560
"I created the queries within Access and create a Macro in Access to run all the queries (OpenQuery) one after the other. " this is the main reason for your problem.

As Jadedata has stated, if you want to check on the status of the first query before executing the others, you MUST use VBA code.


This is NOT a job to be carried out with a MACRO - in fact, there is NO JOB that should be carried out with a MACRO.  Microsoft STRONGLY advises AGAINST using Macros - they are supported almost purely for backward compatability with previous versions of Access, and should NOT be used for new databases.

AW
0
 
LVL 32

Expert Comment

by:jadedata
ID: 9897597
Just say "No" to Macros!!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

839 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