I have around 50 queries. These queries are run on a requirement basis.
For example, i have query1,query2,query3,query4,query5
If i select query1,query3 through a check box, the selected query should run.
How can i create a form and call these queries by selecting through check
boxes?
Pls help.
What *are* these queries?
I've *rarely* but occasionally had to have an application run multiple append
or update queries. What I've done is to create a Table, tblQueries, with
fields QueryName (Text, Primary Key), ToBeRun (yes/no), and Sequence (number,
specifying the order in which they are to be run). You can have a Form to open
tblQueries, check the checkboxes, and then have a command button running code
like
Private Sub cmdRunQueries_Click()
Dim db As DAO.Database
Dim qd As DAO.Querydef
Dim rs As DAO.Recordset
Dim strSQL As String
On Error GoTo Proc_Error
Set db = CurrentDb
strSQL = "SELECT tblQueries.QueryName FROM tblQueries WHERE ToBeRun=True" _
& " ORDER BY Sequence;"
Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot)
If rs.RecordCount = 0 Then
MsgBox "No queries to run!
GoTo Proc_Exit
End If
Do Until rs.EOF
Set qd = db.Querydefs(rs!QueryName)
qd.Execute dbFailOnError
rs.MoveNext
Loop
Proc_Exit:
Exit Sub
Proc_Error:
<handle the error condition with appropriate messages>
Resume Proc_Exit
End Sub
John W. Vinson [MVP]