Converting Select Query to Make Table in Code

  • Thread starter Thread starter Kitty
  • Start date Start date
K

Kitty

I have a select query that most of the time is appropriate
to be one.

Occasionally, I need the same query to create a table.

Is there a way to change the query type at run time,
probably from code behind a form?

Thanks.

Kitty
 
The simplest way is to execute a Make Table SQL statement that uses the
query as its source:

CurrentDb.Execute "SELECT * INTO NewTable FROM qrySelect", dbFailOnError

... where "qrySelect" is the name of your Select query.

--
John Viescas, author
"Microsoft Office Access 2003 Inside Out"
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
http://www.viescas.com/
(Microsoft Access MVP since 1993)
 
Either create the query with code (build a SQL string, save it as a new query and run it) or, if the MakeTable query will always be the same, create it in the database and use code or a conditional macro to run them, based on the specific situation

Hope this helps

Howard Brod


----- Kitty wrote: ----

I have a select query that most of the time is appropriate
to be one

Occasionally, I need the same query to create a table

Is there a way to change the query type at run time,
probably from code behind a form

Thanks

Kitt
 
Perfect!

Thanks, John, for your fast response.

Do you have a recommendation for a good SQL source book?
I've got to learn more about it.

Kitty
 
Well, a lot of people like "SQL Queries for Mere Mortals", but some consider
it too simple. It wouldn't have helped you with this problem because it
doesn't cover what Access calls "action" queries - Update, Insert, Delete,
and Select .. Into. We left those out because most implementations
(including Access) stray far from the ANSI standard, which is what we used
as the basis for the book.

--
John Viescas, author
"Microsoft Office Access 2003 Inside Out"
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
http://www.viescas.com/
(Microsoft Access MVP since 1993)
 
Back
Top