Forum Discussion
Access to Word Document
Question: Why does it have to be Word? What is the intended purpose? If you don't want a PDF file, you are likely at a dead end.
If you indeed need a Word document, start with a Word document and import the data to be displayed. In simple cases, a merge document is fine, in complex export the data as an XML file. https://learn.microsoft.com/en-us/office/client-developer/word/content-controls-in-word allow you to display everything that a report can show, including subreports, in one document. Create them with the https://learn.microsoft.com/en-us/dynamics365/business-central/ui-how-add-fields-word-report-layout in the hidden Developer tab.
But beware—this is an advanced topic. At some point, you will want to program in VBA and use XPath. Everything you can do manually can be done in code, but this is not true the other way around.
Example code for exporting a query from Access to Word:
Const WordFilePath As String = "Path to Word report doc"
Dim tmpXmlDataFile As String
tmpXmlDataFile = CurrentProject.Path & "\tmpReportData.xml"
ExportXML acExportQuery, "ReportQueryName", tmpXmlDataFile
Dim WordApp As Object
Set WordApp = CreateObject("Word.Application")
Dim doc As Object
Set doc = WordApp.Documents.Open(WordFilePath, ReadOnly:=False, AddToRecentFiles:=False, Revert:=True, Visible:=True, Format:=9) ' wdOpenFormatXMLDocument=9
doc.CustomXMLParts.Add
doc.CustomXMLParts(doc.CustomXMLParts.Count).Load tmpXmlDataFile
WordApp.Activate