Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Copy AccessDatabase to a flat file

Posted on 2000-05-08
5
Medium Priority
?
178 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 400 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

618 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