RUN MANY QUERIES FROM VBA

  • Thread starter Thread starter NEOFYTOS
  • Start date Start date
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
 
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)
 
Back
Top