Creating a Query Using Code
Sub CreateQuery()
Dim cmd As ADODB.Command
Dim strSQL As String
Dim cat As ADOX.Catalog
Set cat = New ADOX.Catalog
cat.ActiveConnection = CurrentProject.Connection
Set cmd = New ADODB.Command
cmd.CommandText = "Select * From Employees Where State='CA'"
cat.Views.Append "qryCAClients", cmd
cat.Views.Refresh
Set cat = Nothing
Set cmd = Nothing
End Sub
Related examples in the same category