How To: Run TransferText Method on SQL string (instead of actual query)

Posted on 2005-04-19
Last Modified: 2008-02-01
Hello ~

I would like to run the following TransferText command on an SQL string, which I know works (I can execute the SQL string).

    DoCmd.TransferText acExportDelim, , "qryJournalMailing1", "c:\JournalSubs1.txt", True

When I replace "qryJournalMailing1" with my SQL string:

Dim db As Database
Dim strSQL1 As String

Set db = CurrentDb()

    strSQL1 = "SELECT......."
    DoCmd.TransferText acExportDelim, , "strSQL1", "c:\JournalSubs1.txt", True

I suspect "strSQL1" has to be something other than a string.....

Syntax ideas????

Question by:Chi Is Current
    LVL 16

    Expert Comment

    Hi jacobbarnett,

    It has to be a query or a table.  You can create a query from your strSQL1 string and then refer to that query in the TransferText command.

    LVL 16

    Accepted Solution


    BTW, to create a query you'll do something like this:

        Dim strSQL As String
        Dim qrySQL As QueryDef
        strSQL = "SELECT * From MyTable"
        Set qrySQL = CurrentDb.CreateQueryDef("tmp_Query", strSQL)
        CurrentDb.QueryDefs.Append qrySQL
    LVL 2

    Author Comment

    by:Chi Is Current
    Thanks Kelly

    Hmmmm.  I can create the query and refer to it alright....  'Thought it might be more compact to do it right in the module...

    Any way to run the TransferText command on the SQL string as an object???
    LVL 2

    Author Comment

    by:Chi Is Current
    I see what you're saying now w/ QueryDef....  'will try this.

    LVL 2

    Author Comment

    by:Chi Is Current
    OK.  'Seems like I might as well just run the TransferText command on an existing query and leave it at that.  I think it will be OK.  Thank you for the idea & the lesson!

    Best Regards, Jacob

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
    In the article entitled Working with Objects – Part 1 (, you learned the basics of working with objects, properties, methods, and events. In Work…
    What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now