Solved

Need MS ACCESS QUERY

Posted on 2012-04-11
11
351 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 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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 …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

776 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