[AccessD] Turn a recordset into an actual table

Paul Wolstenholme Paul.W at industrialcontrol.co.nz
Tue Oct 26 17:07:20 CDT 2021


Arthur,

Isn't there a saying something like a bird in the hand is worth 1000 in
Hollywood - or is one of us losing his marbles?

As for displaying a random recordset, and even editing it, it can all be
done with a saved query and VBA code:

1) Specify your query:
    Const stVariableQuery = "query173"    ' Name of the saved query.
This must be an existing SELECT query and there is no reason why it can't
be pass-thru.

2) Read the SQL code out of your query if you want to (in a text box or
part of a VBA statement):
 = CurrentDb.QueryDefs(stVariableQuery).sql

3) Change the SQL code in your query at run time.
    CurrentDb.QueryDefs(stVariableQuery).sql = "SELECT * FROM table173"

4) Open the query as a window, but close it first if it was already open:
On Error Resume Next
    ' Close an old version if open
    DoCmd.Close acQuery,  stVariableQuery
On Error GoTo MyErrorHandler
    DoCmd.OpenQuery stVariableQuery, acViewNormal, acReadOnly

If you want to edit records, change the  acReadOnly.

Paul Wolstenholme


More information about the AccessD mailing list