Question : How to export data from Access database?

I have an Access database (import from Excel), in which I have several columns such as: University, General Information, Department/School, Program, Links, Deadline... (total 11 columns)
Now I want to export it to a text file with information like the template below:

1. University Column
Information: from General Information column
Department/School: Department/School column
Program: from Program column
Links: from Links column
Deadline: from Deadline column
......
2. University Column
Information: from General Information column
Department/School: Department/School column
Program: from Program column
Links: from Links column
Deadline: from Deadline column
......
......
How to do like this? I think we can export it to report and copy paste as usual. Please suggest me!

Answer : How to export data from Access database?

Assuming a command button named cmdExport() on a form, to give you exactly what you asked for, the code will go something like this.  Assuming for fields 2 thru 11 you want each line prefixed with the name of the field:

Private Sub cmdExport()
Dim strOutput as String, db as Database, rs as Recordset, i as Long, j as Integer
i = 1    'record counter
Set db = currentdb
set rs = db.OpenRecordSet("myExportTable", dbOpenForwardOnly)
Open "C:\Data\TxtData\LineDelimited.txt" For Output as 1
Do While Not rs.EOF
  Line Output #1, i & ". " & University
  For j = 1 to 10    'field counter
    Line Output #1, rs(j).Name & ": " & rs(j).Value
  Next j
i = i + 1
Loop
Close #1
set rs = nothing
set db = nothing

End Sub
Random Solutions  
 
programming4us programming4us