Solved

Need MS ACCESS QUERY

Posted on 2012-04-11
11
352 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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 …

821 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