Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Copy AccessDatabase to a flat file

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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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
Course of the Month20 days, 18 hours left to enroll

810 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