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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to export access query to .txt

Status
Not open for further replies.

ef61778

IS-IT--Management
Sep 23, 2003
14
US
How do I export an access query to .txt using visual basic?
 
Are You trying to write code in Visual basic to do that?

If so ..
You can use loop to write into file..
using print file#
 
see thread709-492487 (and thread222-660477 but change the SELECT to a SELECT * FROM TheTable) if you want to create a query and insert data to a text file in one action.
 
Here is what I have so far. I saw something like this in Thread709=492487. From that thread however, I don't see how I would create a .txt file form that.

Dim intCounter As Integer

Dim my_Connection As ADODB.Connection
Dim my_Recordset As ADODB.Recordset
Dim strConnection As String

Dim strSql As String

strSql = "SELECT * FROM ProvidedInfo,ReceivableDocument"

strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Test\RecDoc.mdb;Persist Security Info=False"
Set my_Connection = New ADODB.Connection
my_Connection.Open strConnection

Set my_Recordset = New ADODB.Recordset
my_Recordset.CursorType = adOpenKeyset
my_Recordset.LockType = adLockOptimistic
my_Recordset.Open strSql, my_Connection, , , adCmdText

Do While Not my_Recordset.EOF
Debug.Print my_Recordset.Fields("tbl_RecDoc").Value
Debug.Print my_Recordset.Fields("tbl_AccNum").Value
Debug.Print my_Recordset.Fields("tbl_DueDate").Value
Debug.Print my_Recordset.Fields("tbl_MonthAmt").Value
Debug.Print my_Recordset.Fields("tbl_Entity").Value
Debug.Print my_Recordset.Fields("tbl_Type").Value
my_Recordset.MoveNext
intCounter = intCounter + 1
Loop
my_Recordset.MoveFirst



my_Recordset.Close
my_Connection.Close

Set my_Recordset = Nothing
Set my_Connection = Nothing
 
>From that thread however, I don't see how I would create a .txt file form that

in my post, change the *.asc to *.txt if that is what you mean.
Like I said, this is if you want to take data (filtered if desired) from a MDB table and put it directly into a text file.
If you have the data already in a recordset, us the method mentioned by Nickel, or the code in Thread222-660477, adding the field values to the SELECT statement.
Keep it simple...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top