Solved

How to determine if a query has executed successfully?

Posted on 2003-12-08
5
635 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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.

749 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