Solved

Copy AccessDatabase to a flat file

Posted on 2000-05-08
5
173 Views
Last Modified: 2010-05-02
I have an AccessDatabase. I need to grab some info from a few fields in an Access table and copy those info to a text file. How should I approach this.
0
Comment
Question by:gabester
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2788774
Open a recordset, loop it writting data to your ASCII file.

Dim intNumFile As Integer

intNumFile = FreeFile
Open "C:\test.txt" For Output As #intNumFile
Do until rst.eof
   Print #intNumFile, rst!Field1 & ", " & rst!Field2
   rst.movenext
loop
Close #intNumFile
rst.close
Set rst = Nothing
0
 
LVL 14

Accepted Solution

by:
wsh2 earned 100 total points
ID: 2788809
Set a reference to "Microsoft ActiveX Data Objects".. assuming you are using Access 97, you can use the following:

<----- Code Begin ----->

Dim dbGet As New ADODB.Connection
dbGet.Provider = "Microsoft.Jet.OLEDB.3.51"
dbGet.ConnectionString = "c:\MyPath\MyFile.mdb"
dbGet.Open

Dim rsGet As New ADODB.Recordset
rsGet.ActiveConnection = dbGet.ConnectionString
rsGet.Source _
   = "SELECT MyField1, MyField2 " _
   & "FROM MyTable "
rsGet.Open

Open "C:\MyPath\MyFile.Text" For OUTPUT As #1
   
With rsGet
   Do Until .EOF
      Write #1, !MyField1, !MyField2
     .MoveNext
   Loop
   .Close
End With

Close #1
     
Set rsGet = Nothing
Set dbGet = Nothing

<----- Code End ----->
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2788826
Emoreau's example will give you a pure Text File.. WSH2's will give you a CSV file suitable for Importing. (CSV means each field will be seperated by a column and the strings will be enclosed in double quotes)
0
 
LVL 2

Expert Comment

by:Simonac
ID: 2788837
U can also use the following function:
appAccess.DoCmd.TransferText

Where appaccess is an access.application
Its the equivalent of using (in access) Export as text file
0
 

Author Comment

by:gabester
ID: 2789247
WSH2 thanks. Your code worked really well.

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

732 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