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 / Modules / DAO / VBA / January 2006

Tip: Looking for answers? Try searching our database.

TransferText - Export

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dan - 06 Jan 2006 00:05 GMT
My problem is that the same basic query needs to be run from different
tables. How can I  create a query at run time and code it to the
docmd.transfertext command.  I have only been able to run a stored query.

dan
Ken Snell (MVP) - 06 Jan 2006 00:28 GMT
Here's some generic code to create a new query from an existing query
(alternatively, you can write your own SQL statement and use it to make the
new query), append it to QueryDefs collection, export it, and then delete
it.

Dim qdf As DAO.QueryDef, qds As DAO.QueryDef
Dim dbs As DAO.Database
Dim intLoop As Integer
Dim strSQL As String, strQ As String

Set dbs = CurrentDb

' Use next four steps if the new query is being copied from
' an existing query
'Set qds = dbs.QueryDefs("QueryBeingUsedAsTemplate")
'strSQL = qds.SQL
'qds.Close
'Set qds = Nothing

' Use next step if you want to build the SQL string for the new query
'strSQL = "Your SQL statement goes here"

strQ = "NameOfNewQuery"
Set qdf = dbs.CreateQueryDef(strQ, strSQL)
qdf.Close
DoCmd.TransferText acExportDelim, "SpecificationName", qdf.Name, _
   "ExportToFile.txt", True
dbs.QueryDefs.Delete strQ
Set qdf = Nothing
dbs.Close
Set dbs = Nothing

Signature

       Ken Snell
<MS ACCESS MVP>

> My problem is that the same basic query needs to be run from different
> tables. How can I  create a query at run time and code it to the
> docmd.transfertext command.  I have only been able to run a stored query.
>
> dan
Dan - 06 Jan 2006 14:16 GMT
Ken,
thanks for the quick response.  I am using ado not dao.  
Is the best way to solve the problem create a temp query? If so, how do I do
that?

Dan

> Here's some generic code to create a new query from an existing query
> (alternatively, you can write your own SQL statement and use it to make the
[quoted text clipped - 33 lines]
> >
> > dan
Ken Snell (MVP) - 06 Jan 2006 17:03 GMT
Use DAO instead of ADO for this particular action.

The "second" option in the code that I posted shows how to create a
temporary query (see the line with CreateQueryDef in it).

Signature

       Ken Snell
<MS ACCESS MVP>

> Ken,
> thanks for the quick response.  I am using ado not dao.
[quoted text clipped - 43 lines]
>> >
>> > dan
 
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.