Forum Discussion
Maxine14062
Oct 31, 2024Copper Contributor
Access to Word Document
Office 365. I have an Access report with one image (logo) and 4 subreports as a Print Preview. I need to save it as a Word .docx. Would it be best to just use the export to word command on the P...
Ken_Sheridan
Nov 02, 2024Copper Contributor
If you output an Access report to a PDF file, and then open the file in Word it will be converted to an editable version of the file, which can then be saved as a Word .docx file. Images will be preserved in the .docx file.
For an illustration of how to output a report (invoice) as a PDF file you might like to take a look at InvoicePDF.zip in my public databases folder at:
https://onedrive.live.com/?id=44CC60D7FEA42912%21169&cid=44CC60D7FEA42912
In this little demo file a button on the main invoices form outputs the current invoice report to a PDF file, which can be opened in Word and saved as a .docx file.
For an illustration of how to browse to a file in Access, and then open (or print where appropriate) the file in the default application for the file type, take a look at BrowseDemo.zip in my same OneDrive folder. The file will not reflect any changes in the data in Access since the file was created. For that you’d need to output the Access report to a PDF file again.Maxine14062
Maxine14062
Nov 03, 2024Copper Contributor
Thanks, that worked great. The next part of the issue is to open Word and the created PDF from inside Access. A Macro would be good.
- Ken_SheridanNov 04, 2024Copper Contributor
I gave you a link in my last reply to my BrowsDemo file in my public databases on OneDrive. The demo includes the following module:
' module basShellExecute
Option Compare Database
Option Explicit
Public Const SW_HIDE = 0
Public Const SW_SHOWNORMAL = 1
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_SHOWMAXIMIZED = 3
Public Const OP_OPEN = "Open"
Public Const OP_PRINT = "Print"
Declare PtrSafe Function ShellExecute& Lib "shell32.dll" Alias "ShellExecuteA" (ByVal _
hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal _
lpParameters As String, ByVal lpDirectory As String, ByVal nshowcm As Long)
Sub ShellToFile(strPath As String, _
Optional strOperation As String = OP_OPEN, _
Optional lngShow As Long = SW_SHOWNORMAL)
Dim lngRetVal As Long
Dim lngHwnd As Long
lngHwnd = Application.hWndAccessApp
lngRetVal = ShellExecute(lngHwnd, strOperation, strPath, _
vbNullString, CurDir, lngShow)
If lngRetVal < 32 Then
MsgBox "Unable to open/print file " & strPath, vbInformation, "Warning"
End If
End Sub
Add the module to your database. To open a file in its associated application you would call the ShellToFile procedure like this:
ShellToFile “C:\MyWordFiles\MyFile.docx”