Non Mail Merge Operations Sending Access Data to Word

In addition to using VBA within Access to create a mail merge, you can also export just about any information within Access to Word using VBA and the Word object model. As a short example, the following code uses the CommonDialog control to allow a user to export an Access report to a specific Word document. You might want to do this if you have users who need to modify the report or need to perform other operations such as sending an external document to the report or e-mailing the report to others in an editable format.

Dim objWordApp As Word.Application Dim objWord As Word.Document

Dim strFilePath As String

Me.cmdlg.DialogTitle = "Choose File Name and Location"

Me.cmdlg.ShowOpen strFilePath = Me.cmdlg.FileName

DoCmd.OutputTo acOutputReport, "Samples", acFormatRTF, strFilePath Set objWordApp = CreateObject("Word.Application") Set objWord = objWordApp.Documents.Open(strfilePath)

' Make Word visible. objWord.Application.Visible = True Set objWord = Nothing Set objWordApp = Nothing

0 0

Post a comment