Generate MS-Word documents (1 Viewer)

Motorhead

Registered User.
Local time
Today, 15:29
Joined
Feb 19, 2002
Messages
11
Hello!

Anyone knows where I can find some information and example code for generating an MS-Word document with VBA?
The MS-Word document must be based on a query or an table.

Thanx,

Martijn
 

The Member

Registered User.
Local time
Today, 15:29
Joined
Nov 2, 2001
Messages
21
Shall you wish to have a quick go, I have tried this and it worked.

Go to the Code, and then use the outputto method. high light it use F1 it tell you every thing you need to know.

at the example below I exported a table "tblMemoField" to Excel...

you would need to specify what to output, ("acOutputTable", you can also do Query, forms etc), which Object to out put ("tblMemoField") into what format ("acFormatXLS"), and then the path to store the file "C:\Test.Xls", and then to auto start it (True), at here we set it true, so you would see it openned in Excel.

Public Sub TestExportExcel()

DoCmd.OutputTo acOutputTable, "tblMemoField", acFormatXLS, "C:\Test.Xls", True

End Sub

Modify the code as such it do it into Word...

Public Sub TestExportWord()

DoCmd.OutputTo acOutputTable, "tblMemoField", acFormatTxt, "C:\Test.Doc", True

End Sub


The limitation is that the outout to word only gives how it looks, since it is from a table to a word document, the display will shows boxes.. but the excel works perfectly.

I would assume the report should transfer quite nicely.
 

Motorhead

Registered User.
Local time
Today, 15:29
Joined
Feb 19, 2002
Messages
11
Thanx, I think it will work perfectly for generating a document of a query.
But I also have to generate a document of a form wich is a little bit more complex, It has to have a special lay-out. But I've got some example code for this, so.
Greetz,

Martijn
 

Users who are viewing this thread

Top Bottom