Solved

How to determine if a query has executed successfully?

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

762 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