Link to home
Start Free TrialLog in
Avatar of gabester
gabester

asked on

Copy AccessDatabase to a flat file

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.
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

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
ASKER CERTIFIED SOLUTION
Avatar of wsh2
wsh2

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wsh2
wsh2

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)
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
Avatar of gabester

ASKER

WSH2 thanks. Your code worked really well.