RUN MANY QUERIES FROM VBA

N

NEOFYTOS

HELLO MY NAME IS NEOFYTOS

i have five queries that i use them in order to delete at the same time
related records in one database

i want these five queries to run at the same time
what code i have to use in vba in order to run these queries from a command
button.
my queries name is for example Q1,Q2,Q3,Q4,Q5
 
D

Douglas J. Steele

Private Sub MyButton_Click()
On Error GoTo Err_MyButton_Click

Dim dbCurr As DAO.Database

Set dbCurr = CurrentDb()
dbCurr.QueryDefs("Q1").Execute dbFailOnError
dbCurr.QueryDefs("Q2").Execute dbFailOnError
dbCurr.QueryDefs("Q3").Execute dbFailOnError
dbCurr.QueryDefs("Q4").Execute dbFailOnError
dbCurr.QueryDefs("Q5").Execute dbFailOnError

End_MyButton_Click:
Set dbCurr = Nothing
Exit Sub

Err_MyButton_Click:
MsgBox Err.Number & ": " & Err.Description
Resume End_MyButton_Click

End Sub

(Replace "MyButton" with the actual name of your command button)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top