0

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!

3
  • What do you mean by "run all" ? Are these action queries ? Or SELECT queries that you want to open ? Or are these queries dependant of each other ? Commented Oct 8, 2012 at 19:20
  • Are they SELECT queries that you just want returned in one recordset? Commented Oct 8, 2012 at 19:22
  • I know you can do a select from an access query, but I just want to run them. These are all ACTION queries (INSERT). Hope that provides more insight. Commented Oct 11, 2012 at 15:12

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.