How to execute a Select query with querydefs

  • Thread starter Thread starter Karen Middleton
  • Start date Start date
K

Karen Middleton

I have two distinct problems I want to execute a select query with the
following

CurrentDb().QueryDefs("Query1").Execute

appears I cannot execute a select query with the above.

Can you please share a code segment how I can execute a select query
from the above and read the recordset and display the output like a
regular access query output.

Some of my queries are quite complex and the fields need to be
computed or calculated in a complex way I need to use VBA to read the
recordset and manipulate the recordset and display it in the same form
as a regular Access query.

I would appreciate if somebody could kindly share the code for reading
from a recordset.

Thanks
Karen
 
Execute only works with Action queries (SELECT INTO, UPDATE, DELETE)

I'm not sure exactly what you mean by "read the recordset and display the
output".

If you want to open the query in datasheet mode (as if you'd clicked on the
query itself in the GUI), you can use:

DoCmd.OpenQuery "Query1"

If you want a recordset that you can manipulate, you can use:

Set rsCurr = CurrentDb().QueryDefs("Query1").OpenRecordset

Check the Help file for both: there are additional parameters that can be
specified.
 
Back
Top