Solved

how to export from microsoft access 2010 to txt (tab delimited)

Posted on 2013-01-15
5
2,228 Views
Last Modified: 2013-01-16
hi

i asked this question yesterday, and i get an answer, and i accepted, and i closed the question; but i have still difficult so i will ask the question again;
i will show you exact what i need, and i hope that someone will be able help with this.

i attached a file called finance.txt,  and this file contained data that i make  manually, and i need to can make file exact like with vba.

so i attached an access database with a table that called table1 and in this table has the same data like in the finance.txt file and the database have a form with a command button "export" but it's not have any code behind that.
 
so i need a vba code (to the export button) to make that it's will export the data on the table "table1" to a file that will seems exact like the finance.txt file

thanks a lot
finance.txt
sample.mdb
0
Comment
Question by:bill201
  • 2
  • 2
5 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 250 total points
ID: 38779466
place this codes in the click event of the button

Private Sub Command0_Click()
Dim rs As DAO.Recordset, strRec As String, j As Integer
Set rs = CurrentDb.OpenRecordset("table1")

Open CurrentProject.Path & "\finance.txt" For Append As #1

Do Until rs.EOF
     For j = 1 To rs.Fields.Count - 1
          If strRec = "" Then
          strRec = rs(j) & vbTab
          Else
          strRec = strRec & rs(j) & vbTab
          End If
     Next
     Print #1, strRec
     rs.MoveNext
     strRec = ""
Loop
Close #1
End Sub

basically that will be the codes that you will use

btw, where did the date column in your text file came from

also, what is the text file formatting, is it Fixed width?

please provide the text formatting
0
 

Author Comment

by:bill201
ID: 38779510
thanks a lot for your answer and the code/
honestly i don't know. i think that its not fixed width. i will try to import (in my other software that called finanda) from this file like is it and i hope that is will be a successful....
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 38779525
did you use an export specification to create the text file?

if you did, upload a copy of the db with the export specification..
0
 
LVL 31

Assisted Solution

by:Helen_Feddema
Helen_Feddema earned 250 total points
ID: 38780254
You can also use the TransferText method to make either a comma-delimited or fixed width text file.  Here are some examples:

Private Sub cmdExportTextDelimited_Click()

   DoCmd.TransferText transfertype:=acExportDelim, _
      specificationname:="CustomerExportSpecs", _
      tablename:="qryCustomers", _
      FileName:="D:\Documents\Examples\Export Delimited.csv", _
      hasfieldnames:=True

End Sub

Private Sub cmdImportTextDelimited_Click()

   DoCmd.TransferText transfertype:=acImportDelim, _
      tablename:="tblMonthlyData", _
      FileName:="D:\Documents\Examples\Monthly Data.csv", _
      hasfieldnames:=False

End Sub

Open in new window

0
 

Author Comment

by:bill201
ID: 38784970
thanks a lot for you both

sorry that i don't response Up to now, i don't was in town and i was not able to test this code. now the two codes are working perfect
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

760 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

19 Experts available now in Live!

Get 1:1 Help Now