Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-01-15
5
Medium Priority
?
2,650 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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 1000 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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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 1000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lost Word File? Eagerly, need it back? Read ahead; this File Recovery guide is for you.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
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…

772 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