Export report to Word document

Nadine67

Board Regular
Joined
May 27, 2015
Messages
225
Hello and thank you for any attention my post may receive.

I have a report in my Access db which I would like to export as a DOC or RTF so that images can be pasted to it, rather than import the images in the db which will take up too much room.

I can successfully export the report as both DOC and RTF which is fine however ideally the document fields and formatting need to be protected, except for the two fields where an image will be pasted. Is this possible? Or is there another file format which will achieve my goal. Or is there another solution such as exporting to a template document?

I would also like to save the document to the user's desktop and open upon export.

Thank you and have a great day!
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Have to confess I've never put an image control on a report, but I suspect it could load the correct image based on a (hidden) textbox that contained the image path for a given record, assuming you're talking about several images related to records. If you're not, and the images have nothing to do with records or no more than one record, that would be easier. Then you export the report as a pdf - no concerns about protection. Saving it to a desktop and causing it to open is definitely all code, and can be a bit problematic what with security issues. Could be done methinks, but there are other ways you might want to deal with it, such as sending the pdf by email instead.
 
Upvote 0
Micron thank you for your reply.

I am starting to think I need a Word doc on the server which is opened and populated from within Access.

I need to make the whole process rather basic for the end-user and so my way of thinking is changing now. I think it might be possible to open a word doc and populate it with the current data and then the user can paste the two images to the relevant fields. My challenge is to come up with the code to enable this..........

Any suggestions as to the code to do this will be greatly appreciated.

Have a great day!
 
Upvote 0
With the doc format, if you add Section breaks either side of where the images are to go and apply 'filling in forms' protection to the document, leaving the Sections where the images are to go unprotected, you can insert the images there. With the docx format, you could do something similar without the need for Section breaks, by applying Word's 'read only (no changes)' protection to the document, marking the locations where the images are to go as exceptions. Of course, if you apply whatever protection you choose to the whole document after adding the images, the issue doesn't arise.
 
Upvote 0
Thank you Macropod.

Ok so this is the code I currently have to open the Word docx (which has certain fields protected). How do I get the protected fields to populate with the data which I have entered on my MS Access form (frmEnter)?

Code:
Private Sub Command34_Click()
Application.FollowHyperlink "S:\14.BEX\STRATEGIC IMPROVEMENT PROCESS\Forms\Strategic Improvement Idea Capture Form - 20160401.docx"
End Sub
 
Last edited:
Upvote 0
Personally, I'd use some fairly standard Word automation code instead of Application.FollowHyperlink. There's plenty of that about for populating formfields, content controls, bookmarks, tables, and mergefields - just choose whatever is appropriate for your situation.
 
Upvote 0
Personally, I'd use some fairly standard Word automation code instead of Application.FollowHyperlink. There's plenty of that about for populating formfields, content controls, bookmarks, tables, and mergefields - just choose whatever is appropriate for your situation.

Paul I am not sure of how to enable Word automation. I know how to 'bookmark' fields on my Word docx and that is about it.
 
Upvote 0
I know how to 'bookmark' fields on my Word docx and that is about it.
Your terminology seems loose. One doesn't ordinarily bookmark fields in Word. One might bookmark a range or insert a formfield (which typically has an internal bookmark name), but one doesn't ordinarily insert a field of some kind then bookmark it. Perhaps you could clarify.

Basic code for Word automation:
Code:
Sub Demo()
'Note: A reference to the Word library must be set, via Tools|References
Dim wdApp As New Word.Application, wdDoc As Word.Document, StrName As String
Const TmpltNm As String = "S:\14.BEX\STRATEGIC IMPROVEMENT PROCESS\Forms\Strategic Improvement Idea Capture Form.dotx"
If Dir(TmpltNm) = "" Then Exit Sub
StrName = Split(TmpltNm, ".dotx")(0) & " - " & Format(Now, "YYYYMMDD")
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Add(Template:=TmpltNm, Visible:=True)
With wdDoc
  'update the document
  
  'save & close
  .SaveAs Filename:=StrName & ".docx", FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False
  ' and/or:
  .SaveAs Filename:=StrName & ".pdf", FileFormat:=wdFormatPDF, AddToRecentFiles:=False
  .Close SaveChanges:=True
End With
Set wdDoc = Nothing: Set wdApp = Nothing
End Sub
Note that the code assumes you're creating a new document from a Word template. As coded, the above sub assumes you're saving the document back to the same folder as that template and adding the current date to the filename.
 
Upvote 0
Thank you so much Paul.

So your code goes in the word template document or is in the form control of the .accdb?

I do apologise for my confusion.
 
Upvote 0

Forum statistics

Threads
1,213,564
Messages
6,114,334
Members
448,567
Latest member
Kuldeep90

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top