Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copy query to a table

Status
Not open for further replies.

ossse

Programmer
Jun 26, 2007
49
US
I am trying to use VBA to copy query results (a full query table) into a new Table. It sounds easy but I have been struggling with this all day; trying several different approaches with no luck.

A point in the right direction will be much appreciated.

Thanks
 
Have a look at maketable query (SELECT ... INTO ... FROM ...)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you for the quick reply... I've looked at the 'make table queries' but I can't find the correct format to write it in VBA. Do you know another website or a post that has describes it (I can't find one)
 
DoCmd.RunSQL "SELECT ... INTO ... FROM ..."

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
OK, I've semi-taught myself how to set it up and I am still having some problems. When I physically build the 'make-table query' myself it works... so I copied the SQL from that table into the VBA and I am getting an error. (Note: I am using the Concatenate function to create my third field.

Here is my line of code:

DoCmd.RunSQL "SELECT Tasks.taskCEID AS CEID, Tasks.taskID AS taskID2, Concatenate("SELECT taskCauseFailureCause FROM TaskCauses WHERE taskCauseTaskID=""" & [taskID]) AS Cause INTO test2 FROM Tasks ORDER BY Tasks.taskCEID, Tasks.taskID;"

The error that I am getting is "compile error: expected end of statement". and then the bolded 'SELECT' gets highlighted.

Any Ideas? Thanks
 
What about this ?
Code:
DoCmd.RunSQL "SELECT taskCEID AS CEID,taskID AS taskID2,Concatenate('SELECT taskCauseFailureCause FROM TaskCauses WHERE taskCauseTaskID=' & [taskID]) AS Cause INTO test2 FROM Tasks ORDER BY taskCEID,taskID;"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Works great! When I run it, a pop up window always asks me

"You are about to paste 190 row(s) into a new table.... do you want to continue... Yes/No"

Is there a way to prevent this pop up window? If not, it's no big deal
 
docmd.setwarnings false to turn off popup message

docmd.setwarnings true to turn on
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top