Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

910 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