One other question, I was opening an existing query that
has parameters of fields coming from an open form. When
i run the code, error about not inputing parameters.
This is a peculiar problem that comes from Access being too nice to you.
When a query runs in the GUI, Access will go through the sql and work out
any vba functions, calls to other parts of the GUI such as form controls,
etc before handing off to Jet.
Unfortunately when you use VBA to pass a query directly to Jet, none of
that happens, and your SQL must be valid and make sense to the dbengine.
This means no custom functions, no controls etc.
One possibility is to substitute the values into the SQL:
strSQL = "SELECT This, That, TheOther " & _
"FROM Somewhere " & _
"WHERE Base = """ & lstBase.Value & """; "
or, somewhat neater, to fill in the parameters yourself
Set qdf = QueryDefs("qryMyQuery")
With qdf
' This is a "normal" one
.Parameters("TopLevel") = txtTopLevel.Value
' You can leave the parameters the same; after all it's
' only a name
.Parameters("Forms!frmLevels!txtBottomLevel") = txtBottomLevel
' if you know the order of the parameters, you can use
' the index, but it's liable to break if you edit the query
.Parameters(3) = "Eric"
.Execute dbFailOnError
End With
Hope that helps
Tim F