Hello,
I am not sure how to accomplish my goal-
I have some code that creates queries based on a value in a checkbox.
So, depending on that value, the queries may or may not exist.
I need to take those queries (if the exist) and create one union query.
This code (cobbled together from bits and pieces I found in forums like this one) creates the first query beautifully, but it won't union the second query.
Obviously, you can tell that I don't know what I am doing, and I humbly admit that. All help is greatly appreciated!
I am not sure how to accomplish my goal-
I have some code that creates queries based on a value in a checkbox.
So, depending on that value, the queries may or may not exist.
I need to take those queries (if the exist) and create one union query.
This code (cobbled together from bits and pieces I found in forums like this one) creates the first query beautifully, but it won't union the second query.
Code:
Private Sub cmdSubmit_Click()
Dim blnQueryExists As Boolean
Dim cat As New ADOX.Catalog
Dim cmd As New ADODB.Command
Dim qry As ADOX.View
blnQueryExists = False
Set cat.ActiveConnection = CurrentProject.Connection
For Each qry In cat.Views
If qry.Name = "qryAgencySelectQuery" Then
cmd.CommandText = "SELECT qryAgencySelectQuery.PID, qryAgencySelectQuery.RECID, ""Agency"" AS [Table] FROM qryAgencySelectQuery"
cat.Views.Append "qrySelectTotal", cmd
Exit For
If qry.Name = "qryProgramSelectQuery" Then
cmd.CommandText = "UNION SELECT qryProgramSelectQuery.PID, qryProgramSelectQuery.RECID, ""ProgStat"" AS [Table] FROM qryProgramSelectQuery"
cat.Views.Append "qrySelectTotal", cmd
Exit For
End If
End If
Next qry
'End If
End Sub
Obviously, you can tell that I don't know what I am doing, and I humbly admit that. All help is greatly appreciated!
Last edited: