Solved

How to determine if a query has executed successfully?

Posted on 2003-12-08
5
620 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 500 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

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

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

22 Experts available now in Live!

Get 1:1 Help Now