Solved

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

Posted on 2013-01-15
5
2,428 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 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 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 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

749 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