Solved

Need MS ACCESS QUERY

Posted on 2012-04-11
11
353 Views
Last Modified: 2012-04-14
I need a query in access that run the three actions below in one action, like a sub-query style.
so I created a query that will drop the tables, and i created a saved import that imports the tables.
What I need is to be able to run a single action that will run all three of these task,
1. qry_drop ( Query that drops the tables)
2. qry_import ( a Saved import that imports the tables)
3. facilityCharges ( the query that needs to run)
0
Comment
Question by:TheonW
[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
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 37833944
create a macro with Action (save macro as myMacro)

Action
RunCode


Function Name  RunMyQueries()



Create a function in a Regular module

Function RunMyQueries()

docmd.openquery "qry_drop"
docmd.openquery "qry_Import"
docmd.openquery "facilityCharges"

end function


now all you need to do is call the macro  MyMacro to run the queries
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37833998
<No Points wanted>

Note that in cases like this, you will need iron-clad error handling and perhaps "Rollbacks" in case one of the queries fails...
...and/or the results of one query are dependent on the results of another...
0
 
LVL 3

Author Comment

by:TheonW
ID: 37834024
boag you are correct, I will need error handling,  since all queries depend on the success of the first ones, for example, their needs to be a check to see if the tables exsist, if not then run the second query, if they do then run the drop query. We have to make sure that the tables are dropped and  imported everytime to get the current data.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37834110
just revised the function to include the checking


Function RunMyQueries()

docmd.openquery "qry_drop"

'place code here to check if query runs properly

docmd.openquery "qry_Import"

'place code here to check if query runs properly
docmd.openquery "facilityCharges"

end function
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37834272
capricorn1 has now got you covered...
;-)
0
 
LVL 5

Expert Comment

by:ggzfab
ID: 37841993
Instead of the drop & import you could use a linked table and define a query holding the facilityCharges logic to create the finally needed table.

Personally I often use an intermediate table holding the sourcedata and an additional runnumber, thus creating a history of imports and the possibility to "go back in time" by filling the final table from a previous runnumber.
0
 
LVL 3

Author Comment

by:TheonW
ID: 37842549
ggzfab, the reason we do not use linked tables is because the query will not run in a timely manner, when the tables are linked we never get any results and it appears that the query is not even running, if we import the tables the same query runs in about 30 seconds.
0
 
LVL 3

Author Comment

by:TheonW
ID: 37842555
if someone could now just present the error handling procedure, then we can close out this question
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37842583
TheonW,

i think your  original problem have already been given a solution..

post another Q about your other problem.. and in your other question give a thorough explanation of what needs to be checked for your error handling procedures.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37842632
a C grade ?
0
 
LVL 5

Expert Comment

by:ggzfab
ID: 37846275
By using "currentdb.execute" instead of "docmd.openquery" you'll be able to add errorhandling when the query fails.
The format is:
currentdb.execute (" qry_drop",DbFailOnError)

Open in new window

The DbFailOnError will perform a roll-back when things go wrong.

Finally I wouldn't use a macro to start the function as it's easier to start the function from the code behind a button.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

751 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