How create a Word Document from Access?

P

PeP

Hi,
I have a form with some comboboxes. In this form I do my choices and after,
by pressing a button, I'd like to export values I've chosen to a Word
document.
I can't use Access functions as "Save as", "Export", OutputTo" and so on ...
so the only way I've found to solve my problem is to create a Word Table and
then convert it to text.

But I'd prefer something better. How?

My code is:

Private Sub ExportToWord_Click()
Dim myAppl As New Word.Application
Dim myDoc As Word.Document
Dim myTable As Word.Table

myAppl.Visible = True
Set myDoc = myAppl.Documents.Add(, , , Visible)
Set myTable = myDoc.Tables.Add(mioDoc.Range(), 4, 1)

myTable.Cell(1, 1).Range.Characters.Item(1) =
[Forms]![Form_Name].FieldName1.Column(0)
myTable.Cell(2, 1).Range.Characters.Item(1) =
[Forms]![Form_Name].FieldName2.Column(0)
myTable.Cell(3, 1).Range.Characters.Item(1) =
[Forms]![Form_Name].FieldName3.Column(0)
myTable.Cell(4, 1).Range.Characters.Item(1) =
[Forms]![Form_Name].FieldName4.Column(0)

myTable.Rows.ConvertToText Separator:=wdSeparateByParagraphs,
NestedTables:=True
Set myTable = Nothing
End Sub

Thanks.

P.S.: I use Access 2000.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top