Let's say I have 3 queries:
- Query1
- Query2
- Query3
And I want to run them all by running a single query QueryRunAll. How can I run Query1, Query2, and Query3 within QueryRunAll?
Thanks much!
Since Query1, Query2, and Query3 are all INSERT queries, the only way you could run them all from a single query, QueryRunAll, is with a user defined function.
If you will be running QueryRunAll from inside an Access session, you could use this as its SQL:
SELECT Runall() AS successful;
However if you intend to run QueryRunAll from outside an Access session, it can't use a UDF, so you won't be able to have one query run 3 action queries.
Public Function Runall() As String
Dim blnReturn As Boolean
Dim db As DAO.Database
Dim strMsg As String
On Error GoTo ErrorHandler
Set db = CurrentDb
db.Execute "Query1", dbFailOnError
db.Execute "Query2", dbFailOnError
db.Execute "Query3", dbFailOnError
blnReturn = True
Set db = Nothing
ExitHere:
Set db = Nothing
Runall = blnReturn
Exit Function
ErrorHandler:
' do more here if desired
GoTo ExitHere
End Function
MS Access (at least 2003) does allow the following syntax for queries which would allow you to run multiple queries together:
SELECT Query1.col1, Query2.col2, Query3.col1
FROM Query1, Query2, Query3
or for INSERT
INSERT INTO yourtable (col1, col2,...)
SELECT Query1.col1, Query2.col2
FROM Query1, Query2, Query3
SELECTqueries that you just want returned in one recordset?