Export records to multiple Word files

J

JoshGautreau

I have an access database with multiple records and information on
each record. I can export the information to one big report, with the
information properly organized, but there are so many records that the
report has become unmanageable.

Is it possible to automatically export each record into it's own word
file, and the file name is automatically saved as the data in one of
the field names?

I can provide further explanation or info if needed.
 
L

Lance

Try this..

Sub exportToFiles()
Dim rs As Recordset
Dim qd As QueryDef
Dim db As Database
Dim i As Integer

Set db = CurrentDb
Set rs = db.OpenRecordset("MY_TABLE")
Set qd = db.QueryDefs("MY_QUERY")


While Not rs.EOF
'Test using smaller dataset!
'For i = 1 To 5
qd.SQL = "SELECT MY_TABLE.* FROM MY_TABLE WHERE MY_TABLE.Last='" &
rs("Last") & "'"
Call DoCmd.OutputTo(acOutputReport, "MY_REPORT", acFormatRTF,
"C:\TEMP_FILES\" & rs("Last") & ".doc")
rs.MoveNext
'Next i
Wend
rs.Close
qd.Close
Set db = Nothing

End Sub
 
L

Lance

One clarification.. "Last" in the example refers to a field named last in the
table I used to test with, it should be replaced by your own field.
 
Top