Solved

Need MS ACCESS QUERY

Posted on 2012-04-11
11
349 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
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero 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
 
LVL 119

Expert Comment

by:Rey Obrero
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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 119

Expert Comment

by:Rey Obrero
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 119

Expert Comment

by:Rey Obrero
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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…

746 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

15 Experts available now in Live!

Get 1:1 Help Now