Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / May 2007

Tip: Looking for answers? Try searching our database.

Form Code to append results from query to table

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Frank - 02 May 2007 20:32 GMT
I have a button on a form that thru code will run a macro which will run a
query.  How do I get the results from that query to append to a table, all
through vb code of my form?

Thanks,
Frank
Carl Rapson - 02 May 2007 23:00 GMT
>I have a button on a form that thru code will run a macro which will run a
> query.  How do I get the results from that query to append to a table, all
> through vb code of my form?
>
> Thanks,
> Frank

Seems to me the easiest way would be for you to skip the macro and use the
query directly in an INSERT statement, something like:

strSQL = "INSERT INTO [table] ([field1],[field2],...) SELECT
[field1],[field2],... FROM [query];"
CurrentDb.Execute strSQL, dbFailOnError

Alternately, you'd have to turn the query into an Append or MakeTable query
somehow.

Carl Rapson
hmadyson - 03 May 2007 02:42 GMT
Here is some code that will do it for you.

Sub RunCode()
Dim qry As QueryDef
Dim strQuery As String

   strQuery = strSQL = "INSERT INTO [table] ([field1],[field2],...) SELECT
" & _
       "[field1],[field2],... FROM [query];"
   Set qry = CurrentDb.CreateQueryDef("", strQuery)
   qry.Execute
   
   Set qry = Nothing
End Sub

just know that if you want to run multiple sql statements, the second time
you should just say qry.sql=strquery rather than creating new query objects.

Please let me know if I can provide more assistance.

> I have a button on a form that thru code will run a macro which will run a
> query.  How do I get the results from that query to append to a table, all
> through vb code of my form?
>
> Thanks,
> Frank
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.